Home >Web Front-end >JS Tutorial >jquery method to determine whether radio button radio is selected_jquery
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.