我正在使用J2EE构建购物车。我需要的是如何在数量变化时更新总价格?我已成功将产品添加到购物车,但我无法动态更新价格。任何人都可以帮助我吗?
var table = $("#cartTB");
$.each(data,function(i, value)
{
table.append
('<tr class="cart_item"><td class="product-remove"><a title="Remove this item" class="remove" href="#">×</a> </td>
<td class="product-thumbnail"><a href=""><img width="145" height="145" alt="poster_1_up" class="shop_thumbnail" src="'+ value.productPic +'"></a></td>
<td class="product-name"><a href="">'+ value.productName +'</a></td>
<td class="product-price"><span id="onePrice" class="amount">'+ value.productPrice +'</span> </td>
<td class="product-quantity"><div class="quantity buttons_added"><input type="button" id="mButton" class="minus" onclick="priceCalc()" value="-"><input type="number" id="qty" size="4" class="input-text qty text" title="Qty" value="'+ value.qty +'" min="0" step="1"><input type="button" id="pButton" class="plus" onclick="priceCalc()" value="+"></div></td>
<td class="product-subtotal"><span id="totProPrice" class="amount">'+ value.productPrice +'</span></td></tr>'
);
我尝试了什么,
function priceCalc()
{
var qty = document.getElementsByClassName("input-text qty text").value;
var total = document.getElementsByClassName("amount").innerHTML * qty;
document.getElementsByClassName("amount").innerHTML = total;
};