jquery Get Radio value

Source: Internet
Author: User

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

Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected

Gets the value of a set of radio selected items
var item = $ (' input[@name =items][@checked] '). Val ();

Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). Checked = True

Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected


The old version of jquery
Var_name = $ ("input[@name = ' radio_name ']:checked"). Val ();
Later versions of jquery 1.3
Var_name = $ ("input[name= ' Radio_name ']:checked"). Val ();


Look at a jquery instance that gets 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 ();
$ ("#isspecialcntno"). Show ();
}
}

<form name= "Form1" method= "Post" action= "" >
<p>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "RADIOGROUP1_0" >
Radio </label>
<br>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "Radiogroup1_1" >
Radio </label>
<br>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "Radiogroup1_2" >
Radio </label>
<br>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "Radiogroup1_3" >
Radio </label>
<br>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "Radiogroup1_4" >
Radio </label>
<br>
<label>
<input type= "Radio" name= "Radiogroup1" value= "Radio" id= "Radiogroup1_5" >
Radio </label>
<br>
</p>
</form>

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.