How to find all unselected checkboxes?

后端 未结 2 1824
梦毁少年i
梦毁少年i 2021-02-19 22:26

In jQuery, how does one go about finding all the \'unchecked\' checked boxes.

$(\':checkbox:checked\');

appears to be me all checked boxes, but

相关标签:
2条回答
  • 2021-02-19 22:55

    A solution without special jQuery selectors, using the attribute selector [docs] and .filter() [docs]:

    $('input[type="checkbox"]').filter(function() {
        return !this.checked;
    });
    
    0 讨论(0)
  • 2021-02-19 23:04

    You use the :not selector, like so:

    $('input:checkbox:not(:checked)');
    

    Or the .not function, like so:

    $('input:checkbox').not(':checked');
    

    Also note that you should always put input before filters like :radio and :checkbox, as without that the selector are evaluated as *:checkbox which is a really slow selector.

    0 讨论(0)
提交回复
热议问题