是我的代码的副本 一旦我填写了表格的详细信息,产品,数量,它显示了价格和总计的子总数,但是当我添加一行新的产品细节时,它不会显示价格或行的总计。
lines
HTML
$(document).ready(function() {
// remove product row
$('#invoice_table').on('click', ".delete-row", function(e) {
e.preventDefault();
$(this).closest('tr').remove();
calculateTotal();
});
// add new product row on invoice
var cloned = $('#invoice_table tr:last').clone();
$(".add-row").click(function(e) {
e.preventDefault();
cloned.clone().appendTo('#invoice_table');
});
$('#invoice_table tbody tr').each(function(e, tr) {
$('#stockID', tr).on('change', function() {
$('#unitPrice', tr).val($('option:selected', this).attr('data-price'));
});
})
calculateTotal();
$('#invoice_table').on('change keyup paste', '.calculate', function() {
updateTotals(this);
calculateTotal();
});
function updateTotals(elem) {
var tr = $(elem).closest('tr'),
quantity = $('[name="quantity[]"]', tr).val(),
price = $('[name="unitPrice[]"]', tr).val(),
total = parseInt(quantity) * parseFloat(price);
$('.calculate-sub', tr).val(total.toFixed(2));
}
function calculateTotal() {
var grandTotal = 0,
disc = 0;
$('#invoice_table tbody tr').each(function() {
var c_sbt = $('.calculate-sub', this).val(),
quantity = $('[name="quantity[]"]', this).val(),
price = $('[name="unitPrice[]"]', this).val(),
total = parseInt(quantity) * parseFloat(price);
grandTotal += parseFloat(c_sbt);
});
// VAT, DISCOUNT, TOTAL, total:
var subT = parseFloat(grandTotal);
$('.total').text(subT.toFixed(2));
}
});