jquery實現購物車的全選與反選


//獲取所有的子按鈕讓下面的去全選按鈕跟着改變
var inputs=$('.Item')
var allinput=$('.qxan')
$(".Item").click(function () {
var s = $(".Item").length;
var a = $(".Item:checked").length;
if (s == a) {
allinput.prop('checked', true);
} else {
allinput.prop('checked', false);
}
});

// 點擊每一家中的商品或者店名前面的的input框時,讓里面額input框也跟着改變  如下圖
$('.diangdan').on('tap','input',function(){
if(this.checked){
$(this).parent().parent().siblings().children().children('input').prop("checked",false);
}else {
$(this).parent().parent().siblings().children().children('input').prop("checked", true);
}
})

//點擊全選事件
$('.qxan').on('tap',function(){
if(this.checked){
$('.Item').prop("checked",false);
}else {
$('.Item').prop("checked", true);
}

})

 

補充說明:

中間的功能是自己按照實際的需求自己進行修改的

前兩個按鈕是一家店鋪,並在里面所購買一種商品

最后一個為全選按鈕

 


免責聲明!

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



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