开发者

checked check box count

开发者 https://www.devze.com 2022-12-19 06:25 出处:网络
How do I count the number of checked chec开发者_运维问答kboxes in a div?var count = 0; var inputs = myDiv.getElementsByTagName(\'input\');

How do I count the number of checked chec开发者_运维问答kboxes in a div?


var count = 0;
var inputs = myDiv.getElementsByTagName('input');
for (var i = 0, j = inputs.length; i<j; i++) {
    var input = inputs[i];
    if (input.type && input.type === 'checkbox' && input.checked) {
        count++;
    }
}
return count;


If you have JQuery on your site you can do it this way (assuming yor div has id='myDiv'):

$("#myDiv input:checkbox:checked").length

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号