find all unchecked checkbox in jquery

后端 未结 8 1221
情歌与酒
情歌与酒 2020-12-04 06:27

I have a list of checkboxes:




        
相关标签:
8条回答
  • 2020-12-04 07:02

    As the error message states, jQuery does not include a :unchecked selector.
    Instead, you need to invert the :checked selector:

    $("input:checkbox:not(:checked)")
    
    0 讨论(0)
  • 2020-12-04 07:04

    $("input:checkbox:not(:checked)") Will get you the unchecked boxes.

    0 讨论(0)
  • 2020-12-04 07:06

    You can do so by extending jQuerys functionality. This will shorten the amount of text you have to write for the selector.

    $.extend($.expr[':'], {
            unchecked: function (obj) {
                return ((obj.type == 'checkbox' || obj.type == 'radio') && !$(obj).is(':checked'));
            }
        }
    );
    

    You can then use $("input:unchecked") to get all checkboxes and radio buttons that are checked.

    0 讨论(0)
  • 2020-12-04 07:17

    To select by class, you can do this:

    $("input.className:checkbox:not(:checked)")
    
    0 讨论(0)
  • 2020-12-04 07:17
    $(".clscss-row").each(function () {
    if ($(this).find(".po-checkbox").not(":checked")) {
                   // enter your code here
                } });
    
    0 讨论(0)
  • 2020-12-04 07:20

    Also it can be achieved with pure js in such a way:

    var matches = document.querySelectorAll('input[type="checkbox"]:not(:checked)');
    
    0 讨论(0)
提交回复
热议问题