cart/index 这里的加减商品数量问题,location.reload()解决了数量不少于0的问题,但是出现新的问题每次都会减1再减1,加1再加1
$(".minus").click(function(){
var cartid = $("input[name=productnum]").attr('id');
var num = parseInt($("input[name=productnum]").val()) - 1;
if (parseInt($("input[name=productnum]").val()) <= 1) {
var num = 1;
}
var total = parseFloat($(".value.pull-right span").html());
var price = parseFloat($(".price span").html());
changeNum(cartid, num);
var p = total - price;
if (p < 0) {
var p = "0";
}
$(".value.pull-right span").html(p + "");
$(".value.pull-right.ordertotal span").html(p + "");
});
$(".plus").click(function(){
var cartid = $("input[name=productnum]").attr('id');
var num = parseInt($("input[name=productnum]").val()) + 1;
var total = parseFloat($(".value.pull-right span").html());
var price = parseFloat($(".price span").html());
changeNum(cartid, num);
var p = total + price;
$(".value.pull-right span").html(p + "");
$(".value.pull-right.ordertotal span").html(p + "");
});
function changeNum(cartid, num)
{
$.get('$url', {'productnum':num, 'cartid':cartid}, function(data){
location.reload();
});
}
请问如何解决??另外有没有一份源码相对完整的代码可以发给我(469251369@qq.com).现在都是在github两边对照代码