最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Count the number of checkboxes selected without reloading the page? - Stack Overflow

programmeradmin2浏览0评论

I'm expanding further on this question.

I currently have an asp hyperlink for Select All (NumberOfCheckBoxes) which works, but what I'm looking to do is add another link, possibly just a standard HTML hyperlink for Uncheck Selected (NumberOfCheckedBoxes) and update the value of NumberOfCheckedBoxes as checkboxes are ticked, without reloading the page.

I have javascript already for unchecking them, but not counting them and printing it to screen.

I'm not sure if JQuery is the way to go with this or just standard Javascript.

Thanks in advance for any help.

I'm expanding further on this question.

I currently have an asp.net hyperlink for Select All (NumberOfCheckBoxes) which works, but what I'm looking to do is add another link, possibly just a standard HTML hyperlink for Uncheck Selected (NumberOfCheckedBoxes) and update the value of NumberOfCheckedBoxes as checkboxes are ticked, without reloading the page.

I have javascript already for unchecking them, but not counting them and printing it to screen.

I'm not sure if JQuery is the way to go with this or just standard Javascript.

Thanks in advance for any help.

Share Improve this question edited May 23, 2017 at 11:51 CommunityBot 11 silver badge asked Aug 20, 2009 at 8:17 LiamGuLiamGu 5,34812 gold badges50 silver badges68 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 12

With jQuery you can:

$("input:checkbox:checked").length;

Try this:

var inputElems = document.getElementsByTagName("input"),
    count = 0;
for (var i=0; i<inputElems.length; i++) {
    if (inputElems[i].type === "checkbox" && inputElems[i].checked === true) {
        count++;
    }
}
发布评论

评论列表(0)

  1. 暂无评论