<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<form name="myform" method="post" action="shi1.jsp"> 
<td> <input type="checkbox" name="test1" value="ww1">ww1 </td> 
<td> <input type="checkbox" name="test2" value="ww2">ww2 </td> 
<td> <input type="checkbox" name="test3" value="ww3">ww3 </td> 
<td> <input type="checkbox" name="test4" value="ww4">ww4 </td> <td> <input name="Submit" type="submit" value="提交" onclick="save()"> 
</form><script>
    var selectnum = 0;
    var chkArr = document.getElementsByTagName("input");
    for(var i=0;i<chkArr.length;i++){
        if(chkArr[i].getAttribute("type") == "checkbox"){
            chkArr[i].onclick = function(){
                if(this.checked) selectnum++;
                else selectnum--;
                if(selectnum > 3){
                    alert("最多选择3个");
                    this.checked = false;
                    selectnum--;
                }
            }
        }
    }
function save(){
if (selectnum ==0) {
alert("至少要选择一个");
return false;
}
}</script></body>
</html>

解决方案 »

  1.   

    <html>
        <head>
    <script type="text/javascript">
      function pointvalue(){
        var point=0;
        for (var i=1;i<5;i++){
                  if(document.getElementById("test"+i).checked){
     point=1;
          }
        }
        if(point==0){alert("至少选择一个")}
      }
            </script>

        </head>
    <body>
    <td> <input type="checkbox" name="test1" value="ww1" >ww1 </td> 
    <td> <input type="checkbox" name="test2" value="ww2">ww2 </td> 
    <td> <input type="checkbox" name="test3" value="ww3" >ww3 </td> 
    <td> <input type="checkbox" name="test4" value="ww4" >ww4 </td> <td> <input name="Submit" type="submit" value="提交" onclick="pointvalue()"> </body>
    </html>
      

  2.   

    学习一下 -------------------------
    http://www.pkwutai.cn/
      

  3.   

    同上但刷新后可用function Form_Validator()
    {
        var point=0; 
        for (var i=1;i <5;i++)

                  if(document.getElementById("test"+i).checked)
      { 
                     point++; 
     if(point > 3)
     {
       alert("最多选择3个");
       return (false);
     }
                   } 
        } 
        if(point==0)
    {
    alert("至少选择一个")
    return (false);

      } 
    </script>
    <form name="myform" method="post" action="shi1.jsp" onSubmit="return Form_Validator()" target="_self"> 
    <td> <input type="checkbox" id="test1" value="ww1" >ww1 </td> 
    <td> <input type="checkbox" id="test2" value="ww2" >ww2 </td> 
    <td> <input type="checkbox" id="test3" value="ww3" >ww3 </td> 
    <td> <input type="checkbox" id="test4" value="ww4" >ww4 </td> <td> <input name="Submit" type="submit" value="提交"> 
    </form>