This article mainly introduces JQuery's method for controlling Radio selection, involving jQuery form operations and mouse event responses. For more information, see the following example. Share it with you for your reference. The details are as follows:
Method 1:
$(function () { $("#spanNan").click(function () { $("#Radio1").attr("checked", true); $("#Radio2").attr("checked", false); }); $("#spanNv").click(function () { $("#Radio2").attr("checked", true); $("#Radio1").attr("checked", false); });})
Method 2: (Simple Method)
$(function () { $("#spanNan").click(function () { //$("#Radio1").attr("checked", true); //$("#Radio2").attr("checked", false); $("#Radio1").click(); }); $("#spanNv").click(function () { //$("#Radio2").attr("checked", true); //$("#Radio1").attr("checked", false); $("#Radio2").click(); });})
Female
Summary:
To implement a single choice for the HTML Radio control, for example, to select a male in this example, you must add the name attribute to Radio with the same value. For example, name = "sex ".
Radio is selected by default:
jQuery(document).ready(function(){ $("input[name=targetBlank]:eq(0)").attr("checked",'checked'); $("input[name=status]:eq(0)").attr("checked",'checked');});
When using jquery to obtain the radio value, the most important thing is to master the use of the jquery selector. in a form, we usually need to obtain the value of the selected radio item, therefore, you need to add checked for filtering, such as the following radio items:
1.Jquery gets the radio Value
2.Jquery obtains the checkbox Value
3.Jquery obtains the select Value
To obtain a radio value, you can use the following methods:
$('input[name="testradio"]:checked').val();$('input:radio:checked').val();$('input[@name="testradio"][checked]');$('input[name="testradio"]').filter(':checked');
It's almost complete. If we want to traverse all radio whose name is testradio, the Code is as follows:
$ ('Input [name = "testradio"] '). each (function () {alert (this. value );});
If you want to obtain a specific radio value, such as the Second radio value, write