通过判断对checkbox的value进行分类,比如:选中的第奇数个checkbox放在一个地,第偶数个放在另一个地,急着用,高人们帮我看看,解决就给分
------解决方案--------------------
var cb = document.getElementsByName( "yourCheckboxName ");
for(var i = 0;i < cb.length;i++){
if(i%2 == 0 && cb[i].checked == true){
alert( "偶数 ");
} else if(i%2 != 0 && cb[i].checked == true){
alert( "奇数 ");
}
}
------解决方案--------------------
<script language=javascript>
function getCheckBox()
{
var a=document.getElementsByTagName( "input ");
var b=new Array();
var c=new Array();
var j=0;
for(var i=0;i <a.length;i++)
{
var s=a[i].type.toLowerCase();
if(s== "checkbox ")
{
if(j%2==0)
b.push(a[i]);
else
c.push(a[i]);
j++;
}
}
alert( "数组b是第奇数个checkbox,长度是: "+b.length+ "数组c是第偶数个checkbox,长度是 "+c.length)
}
</script>
</head>
<body>
<input name= " " type= "checkbox " value= "000000 ">
<input name= " " type= "checkbox " value= "11111111 ">
<input name= " " type= "checkbox " value= "2222222 "> <input name= " " type= "checkbox " value= " ">
<input name= " " type= "checkbox " value= " ">
<input name= " " type= "checkbox " value= " ">
<input name= " " type= "checkbox " value= " ">
<input name= " " type= "checkbox " value= " "> <input name= " " type= "checkbox " value= " ">
<input type= "button " onclick=getCheckBox() value= "getCheckBox() "\>
</body>
</html>
-----------------------
如果是要checked的checkbox,自己再写一个判断即可。