Jquery gets the radio value (single-choice group radio), jqueryradio

Source: Internet
Author: User

Jquery gets the radio value (single-choice group radio), jqueryradio

Radio Group radio: $ ("input [@ type = radio] [@ checked]"). val ();

Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item

Obtains the value of a set of radio selected items.

Var item = $ ('input [@ name = items] [@ checked] '). val ();

The second element of the radio Group is the currently selected value.

$ ('Input [@ name = items] '). get (1). checked = true

Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item

Old jquery version

Var_name = $ ("input [@ name = 'Radio _ name']: checked"). val ();

Versions later than jquery 1.3

Var_name = $ ("input [name = 'Radio _ name']: checked"). val ();

View A jquery instance that obtains the radio value.

Function getra () {var_name = $ ("input [name = 'isspecialcnt ']: checked "). val (); // alert (var_name); if (var_name = '1') {$ ("# isspecialcntyes "). show (); $ ("# isspecialcntno "). hide ();} if (var_name = '0') {$ ("# isspecialcntyes "). hide (); (www.jb51.net) $ ("# isspecialcntno "). show ();}} <form name = "form1" method = "post" action = ""> <p> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_0"> single choice </label> <br> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_1"> single choice </label> <br> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_2"> single choice </label> <br> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_3"> single choice </label> <br> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_4"> single choice </label> <br> <label> <input type = "radio" name = "radiogroup1" value = "single choice" id = "radiogroup1_5"> single choice </label> <br> </p> </form>

How does jQuery obtain the radio value of the selected radio button?

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. <input type = "radio" name = "testradio" value = "jquery gets the radio value"/> jquery gets the radio value
2. <input type = "radio" name = "testradio" value = "jquery get checkbox value"/> jquery get checkbox value
3. <input type = "radio" name = "testradio" value = "jquery gets the select value"/> jquery gets the select value
To obtain a radio value, you can use the following methods:
1,

1. $ ('input [name = "testradio"]: checked'). val (); 2,
1. $ ('input: radio: checked'). val (); 3,
1. $ ('input [@ name = "testradio"] [checked] '); 4,
1. $ ('input [name = "testradio"] '). filter (': checked'); it's almost full. If we want to traverse all radio whose name is testradio, the Code is as follows:

1. $ ('input [name = "testradio"] '). each (function () {2. alert (this. value); 3 .}); if you want to obtain a specific radio value, such as the Second radio value, write
1. $ ('input [name = "testradio"]: eq (1) '). val ()

How can I use jquery to obtain the radio value of the selected button?

Var val;
$ ("# IsExchangeDay"). each (function (){
If ($ (this). attr ("checked ")){
Val = $ (this). attr ("value ")

}

});
Alert (val );

Click it to see if you want it. Don't tell me.

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.