Using JQuery to check if no radio button in a group has been checked

后端 未结 8 1642
太阳男子
太阳男子 2020-12-12 15:42

I\'m sitting with a problem, I need to check with JQuery if no radio button within a radio button group has been checked, so that I can give the users an javascript error if

相关标签:
8条回答
  • 2020-12-12 16:10

    Use .length refer to http://api.jquery.com/checked-selector/

    if ($('input[name="html_elements"]:checked').length === 0) alert("Not checked");
    else alert("Checked");
    
    0 讨论(0)
  • 2020-12-12 16:11

    I think this is a simple example, how to check if a radio in a group of radios was checked.

    if($('input[name=html_elements]:checked').length){
        //a radio button was checked
    }else{
        //there was no radio button checked
    } 
    
    0 讨论(0)
提交回复
热议问题