jQuery和单选按钮组 [英] jQuery and radio button groups
本文介绍了jQuery和单选按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,我想选择未选中任何按钮的所有单选按钮组.
In jQuery, I'd like to select all groups of radio buttons where there are no buttons checked.
或者,有没有一种方法可以选择所有单选按钮组并遍历这些组?
Or, is there a way in which I can select all radio button groups and iterate through the groups?
我正在向页面动态添加N个单选按钮组,并且事先不会知道单选按钮组的名称.
I'm dynamically adding N radio button groups to a page and will not know, before hand, what the names of the radio button groups will be.
推荐答案
查找所有广播组:
var radio_groups = {}
$(":radio").each(function(){
radio_groups[this.name] = true;
})
查找哪个广播组已选中单选框,而没有:
to find which radio group has checked radio boxes and which hasn't:
for(group in radio_groups){
if_checked = !!$(":radio[name='"+group+"']:checked").length
alert(group+(if_checked?' has checked radios':' does not have checked radios'))
}
这篇关于jQuery和单选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文