`

jQuery实现checkbox全选

阅读更多

反选补充:

$(this).attr("checked",!$(this).attr("checked"));
 

第一种

 

$(function() {
    $("#selectall").click(function() {
        $("input[@name='shareuser[]']").each(function() {
            $(this).attr("checked", true);
        });
    });
    $("#deselectall").click(function() {
        $("input[@name='shareuser[]']").each(function() {
            $(this).attr("checked", false);
        });
    });
});

  第二种

 

$("#checkall1").click(
function(){
    if(this.checked){
        $("input[name='courseid']").each(function(){this.checked=true;});
    }else{
        $("input[name='courseid']").each(function(){this.checked=false;});
    }
}
);

  第三种

 

jQuery(‘input[@type=checkbox][name=resourceID]‘).attr(‘checked’,this.checked)

  第四种

 

$(function(){
$(‘#CheckBox3′).click(function(){
$(this).attr(‘checked’) == true?$(‘#inputId’).attr(‘checked’, true):$(‘#inputId’).attr(‘checked’, false);
})
})
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics