可能重复:
How can I clone a row in a table without cloning the values of the input elements inside it?添加行使用jQuery一表,但并不需要它的价值
我试图添加一行到table.i发现我们可以使用克隆。我的桌子上有两个文本框在两个不同的tr。克隆最后一行也复制我的文本框中的值,我不想要?任何想法?
我的代码
$("#table-1 tr:last").clone();
可能重复:
How can I clone a row in a table without cloning the values of the input elements inside it?添加行使用jQuery一表,但并不需要它的价值
我试图添加一行到table.i发现我们可以使用克隆。我的桌子上有两个文本框在两个不同的tr。克隆最后一行也复制我的文本框中的值,我不想要?任何想法?
我的代码
$("#table-1 tr:last").clone();
可能不会停这样
$("#table-1 tr:last").clone().find('input[type=text]').val('');
如果你想添加一行输入,但不是值,你可以不喜欢你有什么,和刚刚清除值:
var row = $("#table-1 tr:last").clone();
row.find('input').each(function(){
$(this).val('')
});
row.appendTo("#table-1")
我假设,与我的答案,你的行有输入..如果你可以发布该行的HTML,我们可以帮助更好。 – hookedonwinter 2010-08-26 16:04:23
就明确克隆后的输入字段:
var row = $("#table-1 tr:last").clone().find(':input').val('').end();
// then add the row at the end of the table
$("#table-1").append(row);
请不要在不同的帐户下重复相同的问题。投票结束,这是重复的:http://stackoverflow.com/questions/3576565/how-can-i-clone-a-row-in-a-table-without-cloning-the-values-of-输入元素 – 2010-08-26 16:04:12