Tôi đã chuẩn bị this jsfiddle mà ilustrates cách tập lệnh của tôi tính hai lần tổng của mỗi giá thuộc tính tùy chọn đã chọn. Làm ơn giúp tôi giải quyết vấn đề này.JS script để tính tổng số tiền tính sai
optionsamount
sai, ý tôi là được tính hai lần .. Tại sao vậy? Cảm ơn
function update_amounts(){
var sum = 0.0;
var optionsamount = 0.0;
$('#basketorder > tbody > .product').each(function() {
$('.selectedoptionselect option:selected').each(function(){
optprice = $(this).attr('price');
optionsamount+= parseFloat(optprice);
})
var qty = $(this).find('.qty option:selected').val();
var price = $(this).find('.price').val();
var amount = (qty*price);
sum+= (amount + optionsamount);
$(this).find('.amount').text(''+ amount.toFixed(2));
});
$('.total').text(sum);
}
trong fiddle bạn không bao giờ gọi hàm 'update_amounts() ' – caramba
thats không phải là điểm tôi tin :) – Europeuser
Vâng, fiddle là khá vô ích. – forgivenson