我正在尝试计算此购物车的行和购物车总数。 我有一个本地存储的数组,为这个html提供数据
var arrayLength = cartarry.length;
for (var i = 0; i < arrayLength; i++) {
var id = cartarry[i].id;
var name = cartarry[i].name;
var price = cartarry[i].price.replace('$',"")
var quantity = cartarry[i].quantity;
var itemcontainer = document.getElementById('myContent');
var itemcard = `
<div class="product" id="${id}">
<div class="product-details">
<div class="product-title">Dingo Dog Bones</div>
<p class="product-description"> ${name}</p>
</div>
<div class="product-price" id='productprice'>${price}</div>
<div class="product-quantity">
<input type="number" id='productquantity' value=${quantity} min="1">
</div>
<div class="product-removal">
<button class="remove-product">
Remove
</button>
</div>
<div class="product-line-price" id='productlineprice' >25.98</div>
</div>
`
;
itemcontainer.innerHTML += itemcard;
calculatetotal()
}
这是我的更新数量函数
/* Update quantity */
function updateQuantity(quantityInput)
{
/* Calculate line price */
var price = parseInt($('.product-price').text());
var quantity = parseInt($(quantityInput).val());
var linePrice = price * quantity;
console.log(price,quantity)
/* Update line price display and recalc cart totals */
$('.product-line-price').each(function () {
$(this).fadeOut(fadeTime, function() {
$(this).text(linePrice.toFixed(2));
recalculateCart();
$(this).fadeIn(fadeTime);
});
});
}
所有行价的输出均为NaN,如图所示。您认为我做错了什么?我该如何解决?