/*************************************************************
名称:adjustreadcheckbox
功能:判断当前CheckBox是否有指定的个数被选中了
参数:itemname,表单项的名字
      checkcount,被选中的个数
返回:true或false
*************************************************************/
function adjustreadcheckbox(itemname,checkcount) {
    var thecheckboxcount;
    thecheckboxcount=0;
    var bootobject=document.all.tags("INPUT");
    for (var i=0;i<bootobject.length;i++) {
if (bootobject[i].name==itemname && bootobject[i].checked) {
thecheckboxcount+=1;
}
    }
    if (thecheckboxcount!=checkcount) {
return(false);
    } else {
return(true);
    }
}

解决方案 »

  1.   

    <form action="1.jsp" name="form" onSubmit="return checkData()">
    <input type=checkbox name=cbx value="1">
    <input type=checkbox name=cbx value="2">
    <input type=checkbox name=cbx value="3">
    <input type=checkbox name=cbx value="4">
    <input type=checkbox name=cbx value="5"><input type="submit" value="提交">
    </form>
    <script language="JavaScript">
    function checkData()
    {
      num=0
      len=document.form.cbx;
      if(len.length){
      for(i=0;i<len.length;i++){
         if(len[i].checked)num++;
         }
      }else {
      if(len.checked)num++;
      }
      if(num==0){
        alert("请您选择!")
        return false
      }
      return true
    }
    </script>
      

  2.   

    谢谢各位大哥了!
    我用wanghr100兄的方法解决了!
    谢谢!