Jquery obtains the radio value instance _ jquery

Source: Internet
Author: User
This article mainly introduces examples of getting radio values by jquery, and summarizes in detail various common methods for obtaining radio values by jQuery, for more information about how to obtain the radio value of jquery, see the following example. The details are as follows:

Radio Group radio:

The Code is as follows:

$ ("Input [@ type = radio] [@ checked]"). val ();

Radio Group radio:

The Code is as follows:

$ ("Input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 to the selected one

Obtains the value of a set of radio selected items.

The Code is as follows:

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

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

The Code is as follows:

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

Old jquery version

The Code is as follows:

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


Versions later than jquery 1.3

The Code is as follows:

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

Jquery instance for obtaining the radio value:

The Code is as follows:

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 ();
$ ("# Isspecialcntno"). show ();
}
}

I hope this article will help you design javascript programs.

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.