gpt4 book ai didi

javascript - jQuery 将文本从
  • 拉到隐藏的表单字段
  • 转载 作者:行者123 更新时间:2023-11-29 22:01:25 26 4
    gpt4 key购买 nike

    我知道我犯了一些简单的错误,但我似乎看不到它。

    <li class="ui-state-default" id="1">Text I want to pull</li>

    $('#control1').prop('value', "test" ); //this works
    $('#control2').prop('value', ('#1').text() ); //this does not work

    //OUTPUT:
    <input type="hidden" name="control1" id="control1" value="test">
    <input type="hidden" name="control1" id="control1" value="">

    我正在使用 $(document).ready(function() {//code });

    我正在用 jQuery 填充列表项的 ID 字段(有 8 个列表项):

    //this code works fine the DOM updates and I have numbered list items id=1...id=4...id=8
    var controlnumber = 1;
    $( "li" ).each(function() {
    $(this).prop('id', controlnumber);
    controlnumber++;
    });

    最佳答案

    首先,它是 $('#1') 而不是 ('#1')

    第二,对于 HTML 4

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number     of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

    因此,将 $('#1') 更改为 $('#A1') 或您喜欢的任何其他以字母开头的名称。

    关于javascript - jQuery 将文本从 <li> 拉到隐藏的表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23548447/

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