Home  >  Article  >  Web Front-end  >  jquery method to determine whether radio button radio is selected_jquery

jquery method to determine whether radio button radio is selected_jquery

WBOY
WBOYOriginal
2016-05-16 16:01:001261browse

The example in this article describes how jquery determines whether the radio button radio is selected. Share it with everyone for your reference. The details are as follows:

The html code is as follows:

<input type="radio" id="d1" name="ra" value="a" checked="checked" />
<input type="radio" id="d2" name="ra" value="b" />
<input type="radio" id="d3" name="ra" value="c" />

1. Get the id when loading the page

$("input[type='radio']").each(function(){
  var id= $(this).attr("id");
  if($("#"+id).attr("checked")=="checked"){
   var fs=$("#"+id).val();
  }
});
var s1 = $(".aa:checked").val(); // .aa 为class
var s2 = $("input[name='ra']:checked").val();

2. Get the id when clicking the button

$(function(){
  $("input[type='radio']").click(function(){
    var id= $(this).attr("id");
    alert(id);
  });
});

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn