开发者

checked check box count

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜