本文重点解决JQ实现购物车全选跟总计全选问题,希望能够帮助到你
//GoodsCheck购物车每个店铺的checkBox
//goods-check购物车所有的checkBox
//ShopCheck店铺全选的按钮
//commlistFrm店铺商品的模块
//allCheck 所有全选按钮
// 购物车全选
$('.ShopCheck').click(function () {
if ($(this).prop("checked") == true) {
$(this).parents('.commlistFrm').find(".GoodsCheck").prop('checked',true);
}else{
$(this).parents('.commlistFrm').find(".GoodsCheck").prop('checked',false);
}
shopAllcheck();
});
$('.GoodsCheck').click(function () {
shopItemCheck(this);
shopAllcheck();
});
function shopAllcheck() {
var item =$('.mui-content').children('.commlistFrm').find('.GoodsCheck').length;//获取购物车checkbox的数量
var item_check = $('.mui-content').children('.commlistFrm').find('.GoodsCheck:checked').length;
if(item ==item_check){
$('.allCheck').prop('checked',true)
}
else {
$('.allCheck').prop('checked',false)
}
}
function shopItemCheck(t){
var item =$(t).parents('.commlistFrm').find('.GoodsCheck').length;//获取购物车checkbox的数量
var item_check = $(t).parents('.commlistFrm').find('.GoodsCheck:checked').length;
if(item ==item_check){
$(t).parents('.commlistFrm').find(".ShopCheck").prop('checked',true);
}else{
$(t).parents('.commlistFrm').find(".ShopCheck").prop('checked',false);
}
}
// 结算全选
$('.allCheck').click(function () {
if(this.checked==true){
$('.goods-check').prop('checked',true);
}
else {
$('.goods-check').prop('checked',false);
}
});
本网刊登的文章均仅代表作者个人观点,并不代表本网立场。文中的论述和观点,敬请读者注意判断。