jQuery中选定单选按钮的数量

问题描述:

假设我有如下几组单选按钮:

suppose I have groups of radio buttons like so:

<label><input type="radio" value="1" name="rdQueen" /> Scaramouche</label> <br />
<label><input type="radio" value="1" name="rdQueen" /> Will you do the</label> <br />
<label><input type="radio" value="1" name="rdQueen" /> Fandango</label> <br />

...稍后在页面中...

... sometime later in the page ...

<label><input type="radio" value="1" name="rdFruit" /> Mango</label> <br />
<label><input type="radio" value="1" name="rdFruit" /> Kiwi</label> <br />
<label><input type="radio" value="1" name="rdFruit" /> Potato</label> <br />

我要做的就是确保从两个组中至少选择了一个..因此,我需要对已选中的单选按钮进行计数,在这种情况下为2.

All I want to do is make sure atleast one of them from both group has been selected.. so I need to count the radiobuttons that have been checked, in this case it'll be 2.

仅,我不确定该怎么做.请帮忙!

Only, I am not sure how to do that. help please!

仅检查那些特定的组:

$(':radio[name="rdQueen"]:checked, :radio[name="rdFruit"]:checked').length;

示例: http://jsfiddle.net/AlienWebguy/HzfKq/