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

$(document).ready(function(){
            $("#allsel").click(function(){
            /*
                var is = $(this).attr("checked");
                if(is=="checked"){
                $("table :checkedbox").attr("checked",true);
                }
            */
            //prop
            var is =$(this).prop("checked");
            $("table :checkbox").prop("checked",is);
            
            });
            
            
            $("#notsel").click(function(){
                $("table :checkbox").prop("checked",function(index,attr){
                    return !attr;
                
                });
            
            }
            
            );

        });




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

    //反选
    $('#select-reverse').click(function(){
        checkbox.each(function(i, dom){
            if ( $(dom).attr('checked') ) {
                $(dom).removeAttr('checked');
            } else {
                $(dom).attr('checked', 'checked');
            }
        });
    });
});

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