我正在使用这个jquery 中继器。
我在每次添加表单时都使用自定义计算,比如将一个输入与另一个输入相乘,然后得出相乘结果的总和。
问题是当我们点击删除时,它只是隐藏了行但不删除项目的值,当我们删除另一个项目时,它将删除隐藏的第一个项目并且我的计算得到更新。
我在删除项目时检查类的数量,它在第一次删除时不会减少,它总是在第二次删除时减少,
如何完全删除行及其值?
var _CalTotal = function () {
console.log($(".billitem_quantity").length );
//Calculate total of quantity
var total_quantity = 0;
$(".billitem_quantity").each(function(){
total_quantity += parseFloat($(this).val());
});
$('#itemquantity_total').val(total_quantity.toFixed(2));
**//Calculate total of amount**
var total_amount = 0;
$(".billitem_total").each(function(){
total_amount += parseFloat($(this).val());
});
$('#bill_total').val(total_amount.toFixed(2));
console.log('test');
}
下面是隐藏代码,
hide: function(deleteElement) {
Swal.fire({
title: "Are you sure to cancel this order?",
text: "You will not able to revert this",
icon: "question",
showCancelButton: true,
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, revert it!",
reverseButtons: true,
}).then(function(result) {
if (result.value) {
$(this).slideUp(deleteElement);
//I guess something is missing here to delete that item with first delete fire.
_CalTotal(); //Here i am calling calltotal function.
} else if (result.dismiss === "cancel") {
}
});
},