0
我想克隆一个表格行,并生成一个ID为数组,因为用户可以插入n行。我面临的问题是,我在该表格行中有1个选择下拉选项。如何克隆一个选择以及其他单行的输入标记? (此代码生成2套排在一个时间)两个appendTo的堂妹(的感谢您的帮助克隆选择与其他输入标签一起?
$("#add").click(function() {
$("#comTable tr:eq(0)").clone().find("input").each(function() {
// creates array of ids if the user wants to add more than 1 row so it is N[1], etc
$(this).val('').attr('id', function(_, id) {
return id + 'N' + '[' + i + ']'
});
$(this).val('').attr('name', function(_, name) {
return name + 'N' + '[' + i + ']'
});
}).end().appendTo("#comTable");
$("#comTable tr:eq(0)").clone().find("select").each(function() {
// creates array of ids if the user wants to add more than 1 row so it is N[1], etc
$(this).val('').attr('id', function(_, id) {
return id + 'N' + '[' + i + ']'
});
$(this).val('').attr('name', function(_, name) {
return name + 'N' + '[' + i + ']'
});
}).end().appendTo("#comTable");
i++;
});
谢谢!我正在尝试.find()方式,但最新的编辑似乎是最好的方式! – Nikhil 2012-03-05 17:59:43
但是这在IE中不起作用!任何建议.. – Nikhil 2012-03-05 18:04:14
@Nikhil - 它是否引发错误? – 2012-03-05 19:11:11