jQuery中选定单选按钮的数量 [英] count of selected radio buttons in jquery

查看:78
本文介绍了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/

这篇关于jQuery中选定单选按钮的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆