jQuery 多选与全不选

$("#checkAll").on('click',function(){ //全选按钮
        var flag = this.checked;
        console.log(flag);
        $("input[name='check']").each(function(){
           this.checked = flag;
        })
    })

    $("input[name='check']").on('click',function(){//单个选择按钮
        var length = $("input[name='check']").length;
        var len = $("input[name='check']:checked").length;
        if(length == len){
            $("#checkAll").get(0).checked = true;
        }else{
            $("#checkAll").get(0).checked = false;
        }
    })

  

原文地址:https://www.cnblogs.com/dyy-dida/p/10298659.html