如代码<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="提交">
如果我选择超过3个,就要弹出对话框,提示最多选择三个,请给出代码,小弟初学,线等。

解决方案 »

  1.   


    <html>
    <head>
    <script>
    var checkValue = "";
    function changeCheck(obj){
    if(obj.checked){
    //获取选中的总数
    var length = checkValue.substr(0,checkValue.lastIndexOf(',')).split(',').length;
    if(length+1>3)
    {
    alert('最多只能选择三项');
    obj.checked='';
    }
    checkValue += obj.value+",";
    }
    }
    </script>
    </head>
    <body>
    <input type="checkbox" name="test1" value="ww1" onclick="changeCheck(this)">ww1 <BR>
    <input type="checkbox" name="test1" value="ww2" onclick="changeCheck(this)">ww2 <BR>
    <input type="checkbox" name="test1" value="ww3" onclick="changeCheck(this)">ww3 <BR>
    <input type="checkbox" name="test1" value="ww4" onclick="changeCheck(this)">ww4 <BR>
    <input type="checkbox" name="test1" value="ww5" onclick="changeCheck(this)">ww5 <BR>
    </body>
    </html>