gpt4 book ai didi

Javascript:如何调用
  • 元素值
  • 转载 作者:行者123 更新时间:2023-12-02 19:13:38 25 4
    gpt4 key购买 nike

    任何人都可以给我 javascipt 代码来从我的 HTML 中提取以下 sf_number 实例吗?

    <ul class="multi_value_field" style="width: 99.5%;">
    <li class="choice" choice_id="sf_number">sf_number<a class="close">×</a><input type="hidden" name="ticket[set_tags][]" value="sf_number" style="display: none;"></li>
    <li class="search_field_item"><input type="text" autocomplete="off" tabindex="20"></li>
    </ul>

    基本上,我想将 sf_number 的所有三个实例替换为不同的来自另一个领域的值(value)。这是我尝试提取 sf_number 的代码,但到目前为止还不起作用:

    var n2 = document.getElementsByClassName("multi_value_field").getElementsByClassName("choice");

    提前致谢

    更新如何使用下面您的建议来更改现有代码?

    <html>
    <script type="text/javascript">
    copy = function()
    {
    var n1 = document.getElementById("ticket_fields_20323656");
    var n2 = document.getElementById("choice").getElementsByClassName("sf_number")[0] ;
    n2.value = n1.value;
    }
    </script>

    <input type="button" value="copy" onClick="copy();" />
    </html>​​​​​

    更新

    这似乎不起作用,对吗?

    <html>
    <script type="text/javascript">
    copy = function()
    {
    var fields = document.getElementsByClassName("multi_value_field")[0].getElementsByClassName("choice");

    for (var i = 0; i < fields.length; i++)

    fields[i].setAttribute("choice_id", "document.getElementById("ticket_fields_20323656").value");
    fields[i].getElementsByTagName("input")[0].value = "document.getElementById("ticket_fields_20323656").value";
    fields[i].firstChild.nodeValue = "document.getElementById("ticket_fields_20323656").value";
    }
    </script>

    <input type="button" value="copy" onClick="copy();" />
    </html>​​​​​

    最佳答案

    试试这个代码。您还想替换文本吗?

    <script>
    var fields = document.getElementsByClassName("multi_value_field")[0].getElementsByClassName("choice");

    for (var i = 0; i < fields.length; i++)
    {
    fields[i].setAttribute("choice_id", "something else");
    fields[i].getElementsByTagName("input")[0].value = "something else";
    fields[i].firstChild.nodeValue = "something else";
    }
    </script>

    关于Javascript:如何调用 <li> 元素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13371508/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com