首页 > 如何获取选中的复选框的个数?

如何获取选中的复选框的个数?

<input type="checkbox"> 20
<input type="checkbox"> men 20
<input type="checkbox"> men 30
<input type="checkbox"> 20
<input type="checkbox">
<input type="checkbox"> 33333

<button>aa</button> <button>bb</button>

var box = $('tbody input[type=checkbox]');
            var    size = box.length;//取总个数  
                    
            var    chked = box.filter(':checked').length;//取选中的个数
    
      $('button:contains(aa)').click(function(){
     
          console.log(chked);
          console.log(size);
      
      });

为什么输出的选中的个数为0?


刚好下午整理了这个。
checkbox系列的操作
jQuery操作checkbox


var box = $('tbody input[type=checkbox]');
var size = box.length;//取总个数  

$('button:contains(aa)').click(function () {
    var chked = box.filter(':checked').length;//取选中的个数
    
    console.log(chked);
    console.log(size);

});

你要把获取个数的代码也放进click中。

【热门文章】
【热门文章】