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


posted @ 2015-12-03 09:33  宝贝企鹅  阅读(382)  评论(0编辑  收藏  举报