开发者

Add row to a table with Jquery,but don't need its value [duplicate]

开发者 https://www.devze.com 2023-01-13 00:44 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How can I clone a row in a table without cloning the values of the input elements inside it?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How can I clone a row in a table without cloning the values of the input elements inside it?

i am trying to add a开发者_如何学Python row to a table.i found that we can use clone . my table has two text boxes in it in two different tr's .cloning the last row is also duplicating the values in my textbox's which i don't want ?Any ideas ???

my code

$("#table-1 tr:last").clone();


may be somthing like this

 $("#table-1 tr:last").clone().find('input[type=text]').val('');


If you want to add a row with the inputs, but not the values, you could do something like what you have, and just clear the values:

var row = $("#table-1 tr:last").clone();
row.find( 'input' ).each( function(){
    $( this ).val( '' )
});
row.appendTo( "#table-1" )


Just clear the input fields after cloning :

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

精彩评论

暂无评论...
验证码 换一张
取 消