复选框选中全部无法检测数据

Checkbox Check All unable to detect data

本文关键字:检测 数据 全部 复选框      更新时间:2023-09-26

我在选中勾选所有框的复选框时检索详细信息时遇到问题。当我取消选中它应该在我检查时工作时它可以工作。

当我检查它时,我得到零(右边应该取复选框数据的总和)当我取消选中时,我得到所有复选框数据的总和(右边应该得到零)

我似乎无法"翻转"或意识到这里的逻辑。任何建议将不胜感激。

$(function() {
    var totalPrice = 0.00, 
        totalWeight = 0.00, 
        shippingFee = 0.00, 
        totalCost = 0.00, 
        agentFee = 0.00;
    updateTotals = function() {
        totalPrice = 0.00;
        totalWeight = 0.00;
        shippingFee = 0.00;
        totalCost = 0.00;
        agentFee = 0.00;
        $('#arrange-delivery-table tbody input[type=checkbox]:checked').each(function(i, e){
            totalWeight += Number($(this).data('weight'));
            totalCost += Number($(this).data('cost'));
        });
    };
    $('#arrange-delivery-table :checkbox').change(function(e){
        updateTotals();
    });
});

尝试使用点击事件:

$('#arrange-delivery-table :checkbox').click(function(e){
    updateTotals();
});