请教checkbox的问题
<input type= "checkbox " name= "base " value= "水电 " onClick= "javaScript:Checkbase(); ">
水电
<input type= "checkbox " name= "base " value= "煤气 " onClick= "javaScript:Checkbase(); ">
煤气
<input type= "checkbox " name= "base " value= "天然气 " onClick= "javaScript:Checkbase(); ">
天然气
<input type= "checkbox " name= "base " value= "暖气 " onClick= "javaScript:Checkbase(); ">
暖气
<input type= "checkbox " name= "base " value= "有线电视 " onClick= "javaScript:Checkbase(); ">
有线电视
<input type= "checkbox " name= "base " value= "电梯 " onClick= "javaScript:Checkbase(); ">
电梯
请问怎样写Checkbase才能检查如果有其中一个选了就返回1
没有一个选了的返回2
------解决方案-------------------- <script>
function Checkbase(){
var boxs = document.frm.checkbox;//这你自己改
for (i = 0;i < boxs.length;i ++){
if (boxs[i].checked){
alert( '1 ');
break;
}
}
alert( '2 ');
}
</script>
------解决方案--------------------for (elm in boxs)
{
if (elm.checked)
{
return;
}
}
反了吧老大~?
checked了就return;~?