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