使用Jquery向表添加行,但不需要其值

可能重复:
如何克隆表中的行而不克隆其中的输入元素的值?

我想在table.i中添加一行,发现我们可以使用clone。 我的表中有两个文本框,两个不同的tr.cloning最后一行也复制了我不想要的文本框中的值?任何想法???

我的代码

$("#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" ) 

只需清除克隆后的输入字段:

 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);