How to clear all checkbox When checkbox id=“checkAll” are checked?

后端 未结 4 1960
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 23:04

How to clear all checkbox When checkbox id=\"checkAll\" are checked ?

in my demo , when user checked checkbox id=\"checkAll\" all checkbox are

4条回答
  •  天命终不由人
    2021-01-25 23:36

    You can use change() function and it you can check by using this.checked inside the change event, it will return boolean value for checkbox checked status :

    Check All on Main Checked:

    $('#checkAll').change(function () {    
       $('input:checkbox').prop('checked', this.checked); // all checked on check of #checkAll 
     });
    

    Uncheck All on Main Checked:

    $('#checkAll').change(function () {    
        $('input:checkbox').prop('checked', !this.checked);   // all unchecked on check of #checkAll
         });
    

    if you want all unchecked but no the main check box then:

    Uncheck All Excluding the Main:

    $('#checkAll').change(function () {    
        $('input:checkbox').not(this).prop('checked', !this.checked);   // all unchecked on check of #checkAll but not itself
             });
    

提交回复
热议问题