Simple example of using Jquery to operate radio

Source: Internet
Author: User

<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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.