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
精彩评论