Select all checkbox elements except disabled ones

后端 未结 8 447
暗喜
暗喜 2021-01-18 09:06

I want to select all checkbox elements expect disabled ones,

this is my html



        
相关标签:
8条回答
  • 2021-01-18 09:42
        $('#chkSelectAll').click(function () {
            var checked_status = this.checked;
            //   alert(checked_status);
            $('div#item input[type=checkbox]').each(function () {
                 if(!$(this).is(':disabled'){
                     this.checked = checked_status;
                 }
    
            });
        })
    
    0 讨论(0)
  • 2021-01-18 09:45

    I'd personally suggest:

    $('#chkSelectAll').change(function(){
        var self = this;
        $('input:checkbox').filter(function(){
            return !this.disabled
        }).prop('checked',self.checked);
    });
    

    JS Fiddle demo.

    References:

    • change().
    • :checkbox.
    • filter().
    0 讨论(0)
提交回复
热议问题