Reprint Address http://hi.baidu.com/lipan4/blog/item/8531c62330ee73b04623e886.html
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > <style>
</style>
<title>js gets the value of the check box selected </title>
<body>
<input type= "checkbox" Name= "Aihao" value= "0"/>0
<input type= "checkbox" Name= "Aihao" value= "1"/>1
<input type= "checkbox" Name= "Aihao" value= "2"/>2
<input type= "checkbox" Name= "Aihao" value= "3"/>3
<input type= "checkbox" Name= "Aihao" value= "4"/>4
<input type= "checkbox" Name= "Aihao" value= "5"/>5
<input type= "checkbox" Name= "Aihao" value= "6"/>6
<input type= "checkbox" Name= "Aihao" value= "7"/>7
<input type= "button" onclick= "Chk ()" value= "Submit"/>
</body>
<script src= "Jquery.js" ></script><!--This is a loading jquery.js file that can be removed if you do not use jquery-->
<script>
function Chk () {
var obj=document.getelementsbyname (' Aihao '); Select All Name= "Aihao" objects and return the array
After we take the array of objects, we loop through it to see if it's being checked.
var s= ';
for (var i=0; i<obj.length; i++) {
if (obj[i].checked) s+=obj[i].value+ ', '; If selected, adds value to the variable s
}
So now to detect the value of S, you know the value of the selected checkbox.
Alert (s== '? ') You have not chosen any content yet. ': s);
}
function Jqchk () {//jquery Get check box value
var s= ';
$ (' input[name= ' Aihao ']:checked '). each (function () {
s+=$ (This). Val () + ', ';
});
Alert (s== '? ') You have not chosen any content yet. ': s);
}
</script> Click "Submit", can get the correct choice of the value, but the next one, (English comma), this can be detected and then removed with substring, or get to check box to select the value of the general to be transferred to the number of groups to use, so you can also in the number of groups, Removes the last array element.