Home > Web Front-end > JS Tutorial > body text

jquery method to determine whether radio button radio is selected_jquery

WBOY
Release: 2016-05-16 16:01:00
Original
1262 people have browsed it

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" />
Copy after login

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();
Copy after login

2. Get the id when clicking the button

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template