Finding all checkboxes are checked in jQuery

后端 未结 2 1103
囚心锁ツ
囚心锁ツ 2020-12-14 07:51

I have a collection of checkboxes

 
 
 <         


        
相关标签:
2条回答
  • 2020-12-14 08:07

    I think there would be a good feature in jquery an are function:

    jQuery.fn.are = function(selector) {
    return !!selector && this.filter(selector).length == this.length;
    };
    

    Usage:

    if($('input.paid[type=checkbox]').are(':checked'))
    

    Example:

    http://jsfiddle.net/9s2vA/

    I have found this function at http://api.jquery.com/is/ written by Tgr , when I was checking if this exists.

    0 讨论(0)
  • 2020-12-14 08:21

    Like this:

    if (!$('input.paid[type=checkbox]:not(:checked)').length)
        do('stuff');
    

    This will check if there are any that are unchecked, and do stuff if there aren't (i.e. they are all checked).

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