JQuery实现全选全不选

$('input[name="selectall"]').click(function(){
    //input[name="selectall"]:实现全选与全部选的checkbox
    //alert(this.checked);
    if($(this).is(':checked')){
        $('input[name="stuCheckBox"]').each(function(){
            //input[name="stuCheckBox"]:被选中的CheckBox
            //此处如果用attr,会出现第三次失效的情况
            $(this).prop("checked",true);
        });
    }else{
        $('input[name="stuCheckBox"]').each(function(){
            $(this).removeAttr("checked",false);
        });
        //$(this).removeAttr("checked");
    }

});

<td><input type="checkbox" name="selectall"/></td>
<td><input type="checkbox" name="stuCheckBox" /></td>

猜你喜欢

转载自blog.csdn.net/qq_41054799/article/details/78603830