jQuery使用prop设置checkbox全选、反选

$(function(){
    var checkbox = $("input[type='checkbox']");
    //全选
    $('#select-all').click(function(){
        checkbox.prop("checked", true);
    });
    //反选
    $('#select-reverse').click(function(){
        checkbox.prop("checked", function(index, attr){
            return !attr;
        });
    });

});





    $(document).ready(function(){
            $("#allsel").click(function(){
        
            //prop全选
            var is =$(this).prop("checked");
            $("table :checkbox").prop("checked",is);
            
            });
            
            $("table :checkbox").click(function(){
                $("#allsel").prop("checked",true);
                $("table :checkbox").each(function(){
                    var is = $(this).prop("checked");
                    if(is==false){
                    $("#allsel").prop("checked",false);
                    }
                });
            });
            
            //prop反选
            $("#notsel").click(function(){
                $("table :checkbox").prop("checked",function(i,val){
                    return !val;
                
                });
            
            });
        });
   


原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884832.html