jQuery: how to get the index of a checked radio button

后端 未结 6 1799
再見小時候
再見小時候 2021-02-12 13:03

I recently came across a StackOverflow answer that gave excellent instructions on how to get the value of a checked radio button using jQuery:

var radioVal = $(\         


        
6条回答
  •  悲&欢浪女
    2021-02-12 13:49

    Though this is old, but try this (assuming you're within the click function of the radio buttons)

    $('#myFormID input:radio[name=radioFieldName]').click(function(){
      var index = $('#myFormID input:radio[name=radioFieldName]').index(this);
      alert(index);
    });
    

提交回复
热议问题