jQuery get value of selected radio button

前端 未结 27 1566
耶瑟儿~
耶瑟儿~ 2020-11-22 13:55

The problem statement is simple. I need to see if user has selected a radio button from a radio group. Every radio button in the group share same id.

The problem is

相关标签:
27条回答
  • 2020-11-22 14:37

    Simplest way to get the selected radio button's value is as follows:

    $("input[name='optradio']:checked").val();
    

    No space should be used in between selector.

    0 讨论(0)
  • 2020-11-22 14:37

    Get all radios:

    var radios = $("input[type='radio']");
    

    Filter to get the one that's checked

    radios.filter(":checked");
    

    OR

    Another way you can find radio button value

    var RadeoButtonStatusCheck = $('form input[type=radio]:checked').val();
    
    0 讨论(0)
  • 2020-11-22 14:38
    <input type="radio" class="radioBtnClass" name="numbers" value="1" />1<br/>
    <input type="radio" class="radioBtnClass" name="numbers" value="2" />2<br/>
    <input type="radio" class="radioBtnClass" name="numbers" value="3" />3<br/>
    

    This will return, checked radio button value.

    if($("input[type='radio'].radioBtnClass").is(':checked')) {
        var card_type = $("input[type='radio'].radioBtnClass:checked").val();
        alert(card_type);
    }
    
    0 讨论(0)
提交回复
热议问题