我对某些操作有一个奇怪的问题。我试图像购物车一样计算总物品数量,但有时显示的结果是楠。
var thisID = $(this).attr('id');
var itemname = $(this).find('div .name').html();
var itemprice = $(this).find('div .price').html();
if (include(Arrays, thisID)) {
var price = $('#each-' + thisID).children("li").children(".shopp-price").find('em').html();
var quantity = $('#each-' + thisID).children("li").children(".shopp-quantity").html();
quantity = parseInt(quantity) + parseInt(1);
var total = (parseFloat(itemprice) * parseFloat(quantity)).toFixed(2);
$('#each-' + thisID).children("li").children(".shopp-price").find('em').html(total);
$('#each-' + thisID).children("li").children(".shopp-quantity").html(quantity);
var prev_charges = $('.cart-total').html();
prev_charges = parseFloat(prev_charges) - parseFloat(price);
prev_charges = (parseFloat(prev_charges) + parseFloat(total)).toFixed(2);
$('.cart-total').html(prev_charges);
qte = prev_charges;
}
问题有时候表现得很好而有时则没有。我想知道这是否是一个parseFloat()或parseInt()问题。 这是截屏https://www.screencast.com/t/B4LtcaOD6J5