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);
}

});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM