This example describes the jquery control radio selection method. Share to everyone for your reference. Specifically 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 ();
});
<input id= "Radio2" type= "Radio" name= "Sex"/> "<label" for= "
Radio2" > </label>
Summarize:
HTML radio controls to implement a single selection, such as the choice of men and women in this case, you need to add the Name property to the radio with the same value; Example: Name= "Sex".
Default Selected Radio:
JQuery (document). Ready (function () {
$ ("input[name=targetblank]:eq (0)"). attr ("Checked", ' checked ');
$ ("Input[name=status]:eq (0)"). attr ("Checked", ' checked ');
});
Using jquery to get the value of radio, and most importantly, the use of the jquery selector, in a form where we usually get the value of the selected radio item, we add checked to filter, such as the following radio items:
1.<input type= "Radio" name= "Testradio" value= "jquery gets radio value"/>jquery gets the value of radio
2.<input type= "Radio" name= "Testradio" value= "jquery Gets the value of the checkbox"/>jquery get the value of the checkbox
3.<input type= "Radio" name= "Testradio" value= "jquery Gets the value of a select"/>jquery gets the value of the Select
To get a radio value there are several ways to give the code directly:
$ (' input[name= ' Testradio ']:checked '). Val ();
$ (' input:radio:checked '). Val ();
$ (' input[@name = ' testradio '][checked] ');
$ (' input[name= "Testradio"]). Filter (': Checked ');
It's pretty much all right, if we're going to traverse all the radio of name Testradio, the code is as follows
$ (' input[name= "Testradio"]). each (function () {alert (this.value);});
If you want to take a specific radio value, such as the value of the second radio, write
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("input[@type =radio][name=sex][@ Value=1] "). attr (" Checked ", true);
</script>
Your sex:
<input type= "Radio" name= "Sex" value= "1" <s:if test= "user.sex==1" >checked</s:if>/> male
< Input type= "Radio" name= "Sex" value= "0" <s:if test= "user.sex==0" >checked</s:if>/>
I hope this article will help you with your jquery programming.