Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重置Jquery添加的行空白:_Javascript_Jquery - Fatal编程技术网

Javascript 重置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() {

我正在尝试使用Jquery动态添加一个新行——我可以这样做,只是它精确地克隆了该行,而没有给我一个新的空行

以下是我正在使用的代码:

$('#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的答案——他一行就给了我。