<div id= "Test1" >
<input id= "Radio1" type= "Radio" name= "Radio1" value= "man" >
People
<input id= "Radio2" type= "Radio" name= "Radio1" value= "Ghost" >
Ghost
</div>
There are two ways to implement this in relation to the above:
1, the use of Div ID implementation
#test1 input represents all input elements under the Test1 element
$ ("#test1 input"). Click (function () {
Alert ($ (this). attr ("value"));
2, get all the type of input element, because the single selection may choose one, so this is the currently selected radio box
var radio = $ (' input[type= "Radio"]);
Radio.click (function ()
{
Alert ($ (this). attr ("value")); Take value
});
Here is a Web page special effects get check box value code
<script>
function checkbox ()
{
var str=document.getelementsbyname ("box");
var objarray=str.length;
var chestr= "";
for (i=0;i<objarray;i++)
{
if (str[i].checked = = True)
{
Chestr+=str[i].value+ ",";
}
}
if (Chestr = "")
{
Alert ("Please first choose a hobby ~! ");
}
Else
{
Alert ("Your first choice is:" +chestr);
}
}
</script>
<a href= "http://www.111cn.net" > Web page Making Tutorials </a>Choose your hobby:
<input type= "checkbox" name= "box" id= "Box1" value= "diving"/> Diving
<input type= "checkbox" name= "box" id= "Box2" value= "Running"/> Running
<input type= "checkbox" name= "box" id= "Box3" value= "listening to music"/> Listening to music
<input type= "button" name= "button" id= "button" onclick= "checkbox ()" value= "Submit"/>