Select all checkbox elements except disabled ones

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

I want to select all checkbox elements expect disabled ones,

this is my html



        
8条回答
  •  难免孤独
    2021-01-18 09:23

    $('#chkSelectAll').click(function () {
        var checked_status = this.checked;
    
        $('div#item input[type=checkbox]').each(function () {
               if (!this.disabled) 
                   this.checked = checked_status;
        });
    });
    

    or without the each loop :

    $('#chkSelectAll').on('click', function() {
        var checked_status = this.checked;
    
        $('div#item input[type=checkbox]').prop('checked', function(i, prop) {
             return this.disabled ? prop : checked_status;
        });
    });
    

提交回复
热议问题