article source: http://www.jb51.net/article/64141.htm
first, use to get the selected value to determine the selected
Directly on the code, don't forget to refer to the jquery package
Copy code 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 one!");
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"/>
<br/>
<input type= "Radio" name= "list" value= "very satisfied"/> Very satisfied
<input type= "Radio" name= "list" value= "Satisfaction"/> Satisfaction
<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 "checked" equality, only by using true
Copy code code 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 attribute to judge the selected
Radio cannot be judged by "checked" equality, only by using true
Copy code code as follows:
<script type= "Text/javascript" >
$ (function () {
$ ("Input"). Click (function () {
if ($ (this). attr ("checked")) {
Alert ("Checked");
}
});
});
</script>
<body>
<input type= "Radio"/>
</body>
jquery Gets the value of the Radio radio button
Copy code code as follows:
$ ("Input[name= ' Items ']:checked"). Val ();
Another: Determine if Radio is selected and gets the selected value
As shown below:
Copy code code as follows:
function Checkradio () {
var item = $ (": radio:checked");
var len=item.length;
if (len>0) {
Alert ("yes--selected value is:" +$ (": radio:checked"). Val ());
}
}
get the value of a set of radio selected items
Copy code code as follows:
var item = $ (' input[name=items][checked] '). Val ();
Five, the Set radio button is selected
Copy code code as follows:
$ ("Input[type=radio]"). attr ("Checked", ' 2 ');//Set value=2 item as current selected