当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Checked checkbox in jquery

问题描述:

I have a varible IDs with 3 checkboxes ids (#Id1, #Id2, #Id3).
So when I do $(IDs), I have the list of the checkboxes.

How to know how many checkboxes are checked? I want to trigger the click event on the checked checkboxes.

I try $(IDs + ":checked").click() but the :checked is only on #Id3.

I could do $(IDs).each(...); and do in the function the test if it's checked.

Or change the value of IDs to this : #Id1:checked, #Id2:checked, #Id3:checked.

Is there a way to do it in one line? (or easily)

Thanks

网友答案:

Use filter.

var $checked = $(IDs).filter(':checked');
$checked.click(function() { alert('hello'); });
分享给朋友:
您可能感兴趣的文章:
随机阅读: