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