How can i know which radio input is selected in jQuery?

This question already has an answer here:

  • How can I know which radio button is selected via jQuery? 29 answers

  • 通过使用:

    function getCheckedRadioValue(name) {
      return $('input[name='+name+']:radio:checked').val();
    }
    

    You can do

    $('input[type=radio]').each(function(){
        if($(this).is(':checked')){
            alert('this button is checked');
        }
    });
    

    See the working example below:

    $('button').click(function() {
      var counter = 1;
      $('input[type=radio]').each(function() {
        if ($(this).is(':checked')) {
          alert(' button ' + (counter) + ' is checked');
        }
        counter++;
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type=radio checked />
    <input type=radio />
    <input type=radio checked />
    <button>check</button>
    链接地址: http://www.djcxy.com/p/24588.html

    上一篇: 我如何得到jquery中radiobox的价值

    下一篇: 我怎么知道在jQuery中选择了哪个无线电输入?