How to get value of selected radio button?

前端 未结 28 2172
温柔的废话
温柔的废话 2020-11-22 03:51

I want to get the selected value from a group of radio buttons.

Here\'s my HTML:

28条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 04:49

    HTML CODE:

    JQUERY CODE:

    var value= $("input:radio[name=rdoName]:checked").val();
    

    $("#btnSubmit").click(function(){
    var value=$("input:radio[name=rdoName]:checked").val();
    console.log(value);
    alert(value);
    })
    
     YES
     NO
    

    You will get

    value="YES" //if checked Radio Button with the value "YES"
    value="NO" //if checked Radio Button with the value "NO"
    

提交回复
热议问题