Core code
$ (' div.child:radio:checked ', $ (this). Parents (' div ')). Val ()
There is a special selector: First can be selected, or you can select the first one through the $ (). EQ (1).
jquery is powerful, and you can select the same element in several ways ...
For radio, although not directly supported, there are two ways.
$ (radio). attr ("selected", true);
or $ (radio). Click (function () {});
Look at the example below
<div>
<input id= "Radio1" type= "Radio" Name= "Rad" value= "1" checked/>1
<input id= "Radio2" type= "Radio" Name= "Rad" value= "2"/>2
<input id= "Radio3" type= "Radio" Name= "Rad" value= "3"/>3
<input id= "Radio4" type= "Radio" Name= "Rad" value= "4"/>4
<input id= "Radio5" type= "Radio" Name= "Rad" value= "5"/>5
<input id= "button1" type= "button" value= "button" onclick= "Return Button1_onclick ()"/>
<input id= "button2" type= "button" value= "button" onclick= "Return Button2_onclick ()"/>
</div>
<script language= "Web Effects" type= "Text/javascript" >
<! [cdata[
function Button1_onclick () {
$ ("input"). each (function () {
if (This.type = = ' Radio ') {
Alert ($ (this). Val ());
}
});
}
function Button2_onclick () {
Alert ($ ("input[@type =radio]:checked"). Val ());
Alert ($ ("Input[name= ' rad ']:checked"). Val ());
Alert ($ ("input[@type =radio]"). Val ());
}
]]>
</script>
Code two
<script type= "Text/javascript" src= "Jquery.js" >
</script>
<script type= "Text/javascript" >
$ (function () {
$ (' #form1 '). Submit (function () {
var item = $ (' input[@name =items][@checked] '). Val ();
alert (item);
return false;
});
});
</script>
<title>get Radio Value Document</title>
<body>
<form id= "Form1" >
<input type= "Radio" name= "Items" id= "Item1" value= "a"/>a
<br/>
<input type= "Radio" name= "Items" id= "item2" value= "B"/>b
<br/>
<input type= "Radio" name= "Items" id= "Item3" value= "C"/>c
<br/>
<input type= "Radio" name= "Items" id= "Item4" value= "D"/>d
<br/>
<input type= "Radio" name= "Items" id= "ITEM5" value= "E"/>e
<br/>
<input type= "Radio" name= "Items" id= "Item6" value= "F"/>f
<br/>
<input type= "Radio" name= "Items" id= "Item7" value= "G"/>g
<br/>
<input type= "Radio" name= "Items" id= "ITEM8" value= "H"/>h
<br/>
<input type= "Submit" id= "BTN1" >
</form>
</body>
$ ("Div.child"). Closest ("div")
If you can't determine how to choose, add an ID on the line, you should know that is the preferred way, because ID is the fastest way to query, and through. Class selection is the slowest way