我在表格中选中的复选框发生了一些非常奇怪的事情。我在表格中构建了一个发票计算器,你可以在这里看到它,我的目的是一旦我自动检查输入(Iva 或 Irpef),它们就不会在总金额中计算。正如您在我链接的示例中看到的那样,如果您选中Irpef Input 复选框,它运行良好,Irpef 不在总金额中计算。问题是我的输入复选框 IVA 不会发生同样的情况,为什么?代码完全相同。
当我试图让它们单独工作时,很好,两者都工作得很好,所以看起来他们不能一起工作,可能是?发生了什么?在这个问题上我需要你的帮助。
谢谢
这里是与问题相关的代码:
function tally(selector) {
var total = 0;
$('p.editable_number').each(function() {
total += parseInt($(this).text()) || 0;
$('#subtotal').html(total);
if($("#iva").is(':checked')){
$('#subtotal').html((total).toFixed(2));
$('#total').html((total*0.00).toFixed(2));
$('#total1').html((total*0.15).toFixed(2));
$('#total2').html((total*0.85).toFixed(2));
}
else {
$('#subtotal').html((total).toFixed(2));
$('#total').html((total*0.21).toFixed(2));
$('#total1').html((total*0.15).toFixed(2));
$('#total2').html((total*1.06).toFixed(2));
}
if($("#irpef").is(':checked')){
$('#subtotal').html((total).toFixed(2));
$('#total').html((total*0.21).toFixed(2));
$('#total1').html((total*0.00).toFixed(2));
$('#total2').html((total*1.21).toFixed(2));
}
else {
$('#subtotal').html((total).toFixed(2))
$('#total').html((total*0.21).toFixed(2));
$('#total1').html((total*0.15).toFixed(2));
$('#total2').html((total*1.06).toFixed(2));
}
})
}
$('#irpef').change(function() {
tally('p#subtotal');
tally('p#total');
});
$('#iva').change(function() {
tally('p#subtotal');
tally('p#total');
});