PHP如何实现购物车总计功能
function changeNum(productid, num) {
var goods_numbers=$("input[name='goods_number']");
var goods_prices=$("input[name='goods_price']");
var totalPrice=0.00;
var url = "changeNum.php";
var data = {"productid": productid, "num": parseInt(num)}
var success = function (response) {
if (response.errno == 0) {
var price = $("#product-" + productid).val() * $("#p-" + productid).val();
$("#total-" + productid).html(price);
var goods_numbers=$("input[name='goods_number']");
var goods_prices=$("input[name='goods_price']");
var num=Math.min(goods_numbers.length,goods_prices.length)
var totalPrice=0.00;
for(var i=0;i<num;++i){
var singlePrice=parseInt(goods_numbers[i].value)*parseFloat(goods_prices[i].value);
totalPrice+=singlePrice;
}
$("#total").html(totalPrice);
}
}
$.post(url, data, success, "json");
}