jquery determines whether radio (radio box) is selected and gets the selected value method summary

Source: Internet
Author: User

This article mainly introduced the jquery Judge Radio (single box) whether to select and get the selected value method summary, this article explains the use of the check value to determine the selection, use the Checked property to determine the selected, jquery get Radio radio button value, get a set of radio the value of the selected item, Set the radio button to be selected and other content, the required friends can refer to the following first, use to get the selected value to determine the selectedDirectly on the code, don't forget to refer to the jquery package code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>jquery radio</title>
<script type= "Text/javascript" language= "JavaScript" src= "Javascript/jquery-1.6.1.min.js" ></script>
<script type= "Text/javascript" language= "JavaScript" >
/*------Determine if Radio is selected, get the selected value--------*/
$ (function () {
$ ("#btnSubmit"). Click (function () {
var val=$ (' input:radio[name= ' Sex "]:checked '). Val ();
if (val==null) {
Alert ("Nothing is selected!");
return false;
}
else{
Alert (val);
}
var list= $ (' input:radio[name= ' list "]:checked '). Val ();
if (list==null) {
Alert ("Please select a!");
return false;
}
else{
alert (list);
}
});
});
</script>

<body>
<form id= "Form1" >
<input type= "Radio" name= "Sex" value= "male"/> Male
<input type= "Radio" name= "Sex" value= "female"/> Female
<br/>
<input type= "Radio" name= "list" value= "very satisfied"/> Very satisfied
<input type= "Radio" name= "list" value= "Satisfied"/> Satisfied
<input type= "Radio" name= "list" value= "dissatisfied"/> Dissatisfied
<input type= "Radio" name= "list" value= "very poor"/> very poor
<br/>
<input type= "Submit" value= "Submit" id= "Btnsubmit"/>
</form>
</body>

Radio cannot be judged by the equivalence of "checked", only by using true to judge

The code is as follows:
<script type= "Text/javascript" >
$ (function () {
$ ("Input"). Click (function () {
if ($ (this). attr ("checked")) {
Alert ("Checked");
}
});
});
</script>
<body>
<input type= "Radio"/>
</body>

Second, use the Checked property to determine the selected

Radio cannot be judged by the equivalence of "checked", only by using true to judge

The code is as follows:

<script type= "Text/javascript" >
$ (function () {
$ ("Input"). Click (function () {
if ($ (this). attr ("checked")) {
Alert ("Checked");
}
});
});
</script>
<body>
<input type= "Radio"/>
</body>

Iii. jquery Get the value of radio radio button

The code is as follows: $ ("input[name= ' Items ']:checked"). Val ();
Another: Determine if Radio is selected and gets the selected value

As shown below:
The code is as follows: function Checkradio () {
var item = $ (": radio:checked");
var len=item.length;
if (len>0) {
Alert ("yes--selected value is:" +$ (": radio:checked"). Val ());
}
}

Iv. get a set of values for a radio selected item

The code is as follows: var item = $ (' input[name=items][checked] '). Val ();

V. Set radio button is selected

The code is as follows:
$ ("Input[type=radio]"). attr ("Checked", ' 2 ');//Set the value=2 item as the current selection

Originating From: http://www.jb51.net/article/64141.htm

jquery determines whether radio (radio box) is selected and gets the selected value method summary

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.