//手动输入购物车中的商品数量
$('.num_show').blur(function () {//失去焦点事件
//获取数量和商品id
count = $(this).val()//获取input标签的值
skuid = $(this).attr('skuid')//获取自定义属性的值
//发送请求
if (isNaN(count) || count.trim() || parseInt(count) <= 0){// 三种情况 1.非数字 空格 负数
$(this).val(preCount) //回写数据
return
}
$.ajaxSettings.async = false //同步执行
params = {'skuid':skuid,'goodsCount':count}
$.post('/goods/cartUpdate',params,function (data) { //ajax代码
if(data.res ==5){
err_update = false
totalCount = data.totalCount
}else{
err_update = true
alert(data.errmsg)
}
})
$.ajaxSettings.async = true
if (!err_update){
//重新设置商品数目
$(this).val(count)
//计算商品的小计
price = $(this).parents('ul').children('.col05').text()
amount = count * parseFloat(price)
$(this).parents('ul').children('.col07').text(amount.toFixed(2)+'元')
//获取商品对应的checkbox选中状态,计算总价
is_checked = $(this).parents('ul').find(':checkbox').prop('checked')
if(is_checked){
update_page_info()
}
//更新总件数
$('.total_count').children('em').text(totalCount)
}else{
$(this).val(preCount)
}
})
beego购物车手动修改源码分析
最新推荐文章于 2022-04-22 11:17:35 发布