Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
Forms 为total的表单输入添加唯一ID_Forms_Jquery_Jquery Selectors - Fatal编程技术网

Forms 为total的表单输入添加唯一ID

Forms 为total的表单输入添加唯一ID,forms,jquery,jquery-selectors,Forms,Jquery,Jquery Selectors,我遇到的问题是我正在开发一个发票系统。用这个, $(document).ready(function() { $('#add').click(function() { JQuery('#lineItems').append('<input type="text" name="description[]" class="ui-corner-all text invDesc" /> <input type="tex

我遇到的问题是我正在开发一个发票系统。用这个,

$(document).ready(function() {
    $('#add').click(function() {
       JQuery('#lineItems').append('<input type="text" name="description[]"
           class="ui-corner-all text invDesc" /> 
           <input type="text" name="qty[]" class="ui-corner-all text invQty" /> 
           <input type="text" name="amount[]" class="ui-corner-all text invAmount"
           title="Amount" /> 
           <input type="hidden" name="rowTotal[]" class="row-total-input" />');
    });
   });
但是,它会将所有rowTotal[]输入字段更新为最后一行总计,因此最终的总和不正确

我假设我需要为每个rowTotal[]创建某种唯一的ID,以便只更新正确的ID。我只是不知道怎么做


提前谢谢。

啊,问题在这里:

var qty = $this.parent().find('.invQty').val();
如果每一行都有一个不同的父行,那就可以了,但是所有的“行”都包含在相同的父行项目中。将当前行创建代码更改为:

$(document).ready(function() {
    $('#add').click(function() {
       JQuery('#lineItems').append('<div><input type="text" name="description[]"
           class="ui-corner-all text invDesc" /> 
           <input type="text" name="qty[]" class="ui-corner-all text invQty" /> 
           <input type="text" name="amount[]" class="ui-corner-all text invAmount"
           title="Amount" /> 
           <input type="hidden" name="rowTotal[]" class="row-total-input" /></div>');
         //notice the extra div tag that wrapps around all the input fields
    });
});
$(document).ready(function() {
    $('#add').click(function() {
       JQuery('#lineItems').append('<div><input type="text" name="description[]"
           class="ui-corner-all text invDesc" /> 
           <input type="text" name="qty[]" class="ui-corner-all text invQty" /> 
           <input type="text" name="amount[]" class="ui-corner-all text invAmount"
           title="Amount" /> 
           <input type="hidden" name="rowTotal[]" class="row-total-input" /></div>');
         //notice the extra div tag that wrapps around all the input fields
    });
});