jQuery and radio button groups

后端 未结 3 1902
南旧
南旧 2020-12-06 00:56

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 i

3条回答
  •  渐次进展
    2020-12-06 01:26

    To find all radio groups:

    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'))
    }
    

提交回复
热议问题