jquery Radio Box Radio binding Click event implementation and whether the selected method

Source: Internet
Author: User

Using jquery to get the value of radio, the most important thing is to master the use of jquery selectors, in a form we usually want to get the value of the selected radio item, so add checked to filter, for example, there are some of the following radio items:

1.<input type= "Radio" name= "Testradio" value= "jquery Get Radio Value"/>jquery get Radio value
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 select"/>jquery get the value of select
To get the value of a radio, there are several ways to give the code directly:

1, $ (' input[name= ' Testradio "]:checked '). Val ();
2,$ (' input:radio:checked '). Val ();
3,$ (' input[@name = ' testradio '][checked] ');
4,$ (' input[name= ' Testradio "]). Filter (': Checked ');

Pretty much, if we're going to go through all the radio name Testradio, the code is $ (' input[name= "Testradio"]). each (function() {alert ( this. value); });

If you want to take the value of a specific radio, such as the value of the second radio, write $ (' input[name= "Testradio"]:eq (1) '). Val ()

The following example describes the jquery radio box Radio Binding Click event Implementation method. Share to everyone for your reference.

The implementation method is as follows:

 $(function(){  $(": Radio"). Click (function() {alert ("You are ..." + $ ( This). Val ()); }); });</script><style type= "Text/css" >H5{color:blue;} Textarea{resize:none;} #word {color:red;}</style>male<input type= "Radio" name= "Gender" value= "women" >female<input type= "Radio" name= "Gender" value= "Spring elder brother" >Brother Chun</form></body>

jquery Radio Box Radio binding Click event implementation and whether the selected method

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.