gpt4 book ai didi

javascript - 无法将一个下拉选项复制到另一个

转载 作者:行者123 更新时间:2023-11-30 13:05:22 24 4
gpt4 key购买 nike

我正在尝试将一个下拉列表的值(选项)复制到另一个下拉列表。每次当用户单击添加按钮时,我都会在新的表格行中附加几个文本框和一个作为原始副本的保管箱。下面是我的代码:

$(function(){
$("#addBtn").click(function(){
var rows = $("#nofRowHidden").val();//get the current no of row
rows++;
$("#crsTable").append(
'<tr>'+
'<td><input type="text" name="assesmntNameTxtBx'+rows+'"/></td>'+
'<td><input type="text" name="markRcvdTxtBx'+rows+'"/></td>'+
'<td><input type="text" name="totalTxtBox'+rows+'"/></td>'+
'<td>'+
'<select name="drpDwnCrs'+rows+'">'+
'</select>'+
'</td>'+
'</tr>'
);
//#drpDwnCrs1 was original drbdwn and populated with data from the database
$("#drpDwnCrs1 option").clone().appendTo("#drpDwnCrs"+rows);

$("#nofRowHidden").val(rows);//add current no of row to hidden txt bx
});
});

以上代码正确地生成了带有文本框的新行。但是,无法复制下拉列表的值。

感谢您的帮助。

最佳答案

您正在使用 .appendTo("#drpDwnCrs"+rows) , 其中#id选择器。

当您创建 <select> ,您正在使用 '<select name="drpDwnCrs'+rows+'">'+ .这表明你设置了它的 name属性...而不是 id属性。所以这意味着 appendTo 的 jQuery 选择器调用不会找到任何元素,也不会执行任何操作。

尝试更改我提到的代码:

.appendTo('select[name="drpDwnCrs' + rows + '"]')

关于javascript - 无法将一个下拉选项复制到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872345/

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