Select all checkbox elements except disabled ones

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

I want to select all checkbox elements expect disabled ones,

this is my html



        
8条回答
  •  时光说笑
    2021-01-18 09:41

    Use not() to exclude things with a disabled attribute.

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

    more concise

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

提交回复
热议问题