how to get the values of the radio button which has been checked , jquery

后端 未结 1 1486
不思量自难忘°
不思量自难忘° 2021-02-04 22:53

can we get the values of the radio buttons , only those which has been checked , cause i have to implement a form in which there are many radio buttons , so how can i get all t

相关标签:
1条回答
  • 2021-02-04 23:31

    This would loop through all the radio elements in the document that have been checked:

    $('input:radio:checked').each(function() {
        var value = $(this).val();
        // do something with radio or value
    });
    

    If you wanted to get the checked value of a particular radio group, you would do:

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

    So if your HTML was like this:

    <input type='radio' name='myradios' value='1'>
    <input type='radio' name='myradios' value='2' checked='checked'>
    <input type='radio' name='myradios' value='3'>
    

    value would be 2

    0 讨论(0)
提交回复
热议问题