<Input name = "study" type = "radio" value = "Jquery plugin tutorial"> Jquery plugin tutorial
<Input name = "study" type = "radio" value = "Jquery learning"> Jquery Learning
<Input name = "study" type = "radio" value = "PHP learning"> PHP Learning
<Input id = "tijiao" type = "button" value = "OK">
<Input id = "set_jqeury_study" title = "Jquery learning" type = "button" value = "set radio to Jquery learning">
<Input name = "study" type = "text" value = "Enter the expected information">
<Input id = "view_input_text" type = "button" value = "Click me and you will see the value in the TEXT input box with the same name as 'Study '.">
In the preceding html code, you should be careful to find that the name attribute of three radio and the name attribute of one text are both "study"
Copy codeThe Code is as follows:
$ (Function (){
$ ('# Tijiao'). click (function (){
If ($ ("input: [name = study]: radio: checked"). length = 0 ){
Alert ("select the desired knowledge ");
Return false;
}
Var study = $ ("input: [name = study]: radio: checked"). val ();
Alert ("Thank you! You selected "+ study );
})
$ ("# Set_jqeury_study"). click (function (){
Var $ button = $ (this );
$ ("Input: [name = study]: radio"). each (function (){
If (this. value = $ button. attr ('title ')){
This. checked = true;
}
})
})
$ ("# View_input_text"). click (function (){
Alert ($ ("input [name = study]: text"). val ());
})
})
$ ("Input: [name = study]: radio: checked") This code obtains the jquery objects of all names whose attributes are "study" and have been selected by radio, by judging whether its length is equal to 0, you can know whether this radio option is selected. $ ("Input [name = study]: text") This code obtains the jquery object of the text input box whose name attribute is "study.