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

后端 未结 4 1870
爱一瞬间的悲伤
爱一瞬间的悲伤 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:31

    You shouldn't use the same ID for multiple elements, since IDs are unique. Instead use class="checkedItem".

    If you want to clear all use

    $('#checkAll').click(function () {    
        $('input:checkbox').prop('checked', !this.checked);       
    });
    

    However this also clears the first checkbox. To prevent this use

    $('#checkAll').click(function () {    
        $('input:checkbox').not(this).prop('checked', !this.checked);       
    });
    

提交回复
热议问题