Javascript 重置Jquery添加的行空白:
我正在尝试使用Jquery动态添加一个新行——我可以这样做,只是它精确地克隆了该行,而没有给我一个新的空行 以下是我正在使用的代码:Javascript 重置Jquery添加的行空白:,javascript,jquery,Javascript,Jquery,我正在尝试使用Jquery动态添加一个新行——我可以这样做,只是它精确地克隆了该行,而没有给我一个新的空行 以下是我正在使用的代码: $('#add').click(function(){ $('#invoicetable tbody>tr:last').clone(true).insertAfter('#invoicetable tbody>tr:last') $("#invoicetable tbody>tr:last").each(function() {
$('#add').click(function(){
$('#invoicetable tbody>tr:last').clone(true).insertAfter('#invoicetable tbody>tr:last')
$("#invoicetable tbody>tr:last").each(function() {this.reset().val('');});
return false;
});
您必须用
$(this)
替换此
。
要应用reset()
和val()
,您需要使用jQuery元素并指向表单元素,如下所示:
$('#add').click(function(e) {
e.preventDefault();
$('#invoicetable tbody>tr:last').clone(true).insertAfter('#invoicetable tbody>tr:last');
$("#invoicetable tbody>tr:last").each(function() {
$(this).find('input, select').reset().val('');
});
});
Try
$('#invoicetable tbody>tr:last').clone().find('input').val('').end().insertAfter('#invoicetable tbody>tr:last')可能重复代码>此已修复,请更改您的答案,以便我可以批准它。似乎不起作用,仍然得到相同的输出$(“#添加”)。单击(function(){$(“#invoicetable tbody>tr:last”).clone(true)。insertAfter(“#invoicetable tbody>tr:last”)(“#invoicetable tbody>tr:last”)。每个(function(e){e.preventDefault();//替换返回false$(this.reset().val(“”);});谢谢,我同意@gui47的答案——他一行就给了我。