Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法选择新添加按钮_Javascript_Jquery - Fatal编程技术网

Javascript 无法选择新添加按钮

Javascript 无法选择新添加按钮,javascript,jquery,Javascript,Jquery,我有一个默认为4行的表供用户输入。请看这里的小提琴 当用户单击“添加更多””时,该表将向“标签表””添加具有唯一ID的新行,以及“configtableTable” 有两个错误 1.在生成的“addmore”代码中,应该是按钮的以下代码 id=“开关”+currentIndex+” 2.创建新按钮后,必须为其添加单击事件。 我建议使用以下代码 $('#configsubmit').click(function () { for (var x = 1; x <= currentIndex;

我有一个默认为4行的表供用户输入。请看这里的小提琴 当用户单击“
添加更多”
”时,该表将向“
标签表”
”添加具有唯一ID的新行,以及
“configtableTable”

有两个错误

1.在生成的“addmore”代码中,应该是按钮的以下代码

id=“开关”+currentIndex+”

2.创建新按钮后,必须为其添加单击事件。 我建议使用以下代码

$('#configsubmit').click(function () {

for (var x = 1; x <= currentIndex; x++) {
    $('#label_row_' + x).html($('#label_' + x).val());
}
$('#configtable').show();
$("#configeditdiv").show();
$('#labels').hide();

$("#configtableTable [id^='switch_']:button").unbind('click');
$("#configtableTable [id^='switch_']:button").click(function () {        
    thisIndex = $('td:nth(0)', $(this).closest('tr')).text();
    if (thisIndex === "") {
        thisIndex = 0;
    }
    $('#ptest').append(thisIndex);
    $.post('/request', {
    responseNumber: $('#number_' + thisIndex).val(),
    key_pressed: "activate"
    });
});
$('configsubmit')。单击(函数(){

对于(var x=1;x您的jquery代码在哪里?请尝试更改$(“#configtableTable[id^='switch']:button”)。单击(函数(){到$(“#ConfigTable[id^='switch']:button”)。单击(“单击”,函数(){通常情况下,在处理以数字方式添加的内容时使用on。动态添加的元素或激活按钮中可能没有类似于switch_*的id
 $("#configtableTable").on('click', ".switch", function () {
        thisIndex= $('td:nth(0)',$(this).closest('tr')).text();
        if(thisIndex == ""){thisIndex = 0;}
        $('#ptest').append(thisIndex);
        $.post('/request', {responseNumber:$('#number_'+thisIndex).val(), key_pressed:"activate"});
    });
$('#configsubmit').click(function () {

for (var x = 1; x <= currentIndex; x++) {
    $('#label_row_' + x).html($('#label_' + x).val());
}
$('#configtable').show();
$("#configeditdiv").show();
$('#labels').hide();

$("#configtableTable [id^='switch_']:button").unbind('click');
$("#configtableTable [id^='switch_']:button").click(function () {        
    thisIndex = $('td:nth(0)', $(this).closest('tr')).text();
    if (thisIndex === "") {
        thisIndex = 0;
    }
    $('#ptest').append(thisIndex);
    $.post('/request', {
    responseNumber: $('#number_' + thisIndex).val(),
    key_pressed: "activate"
    });
});