<!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>
<input type="checkbox" id="id1" onclick="check(this,false)">不可<br/>
<input type="checkbox" id="id2" onclick="check(this,false)">不可<br/>
<input type="checkbox" id="id3" onclick="check(this,false)">不可<br/>
<input type="checkbox" id="id4" onclick="check(this,true)">可以<br/>
<input type="checkbox" id="id5" onclick="check(this,true)">可以<br/>
<input type="checkbox" id="id6" onclick="check(this,true)">可以<br/>
<button onclick="fun()">提交</button>
<script type="text/javascript">
var flag = 0;
function check(el,tag)//tag,true表示可以一起选,false表示不可一起选
{
if(!tag)
{
if(el.checked)
flag++;
else
flag--;
}
}
function fun()
{
if(flag>1)
alert("error");
}
</script>
</body>
</html>

解决方案 »

  1.   


    function check(c){
         if(document.getElementById('id1').checked&&document.getElementById('id2').checked
            &&document.getElementById('id4')){
            c.checked=''
            alert('1,2,4 不能同时选择!');
            return false;
         }
         return true;
    }<tr> <td colspan=2 > <input type=submit value="提交" onsubmit='check()'> </tr> 
      

  2.   

    绝对能用。
    <html>
    <head>
    <title>welcome </title>
    </head>
    <script>
      function check(obj){
         var chck1 = document.getElementById('id1');
         var chck2 = document.getElementById('id2');
     var chck3 = document.getElementById('id3');
     var chck4 = document.getElementById('id4');     if(chck1.checked&&chck2.checked&&chck4.checked){
       alert('1,2,4不能同时选中');
     
     }
      
      }  function chck(){
         var chck1 = document.getElementById('id1');
         var chck2 = document.getElementById('id2');
     var chck3 = document.getElementById('id3');
     var chck4 = document.getElementById('id4');
         if(chck1.checked&&chck2.checked&&chck4.checked){
       alert('1,2,4不能同时选中');
       chck1.checked = false;
       chck2.checked = false;
       chck3.checked = false;
       chck4.checked = false;
       return false;
     }
      }
    </script>
    <body>
    <form action="2.asp" method="post" onsubmit="return chck();">
    <table border=1 >
    <tr>
    <td>S1 </td> <td> <input type=checkbox name=num1 id=id1 value="s1" onclick='javascript:check(this)'> </td>
    </tr>
    <tr>
    <td>s2 </td> <td> <input type=checkbox name=num2 id=id2 value="s2" onclick='javascript:check(this)'> </td>
    </tr>
    <tr>
    <td>s3 </td> <td> <input type=checkbox name=num3 id=id3 value="s3" onclick='javascript:check(this)'> </td>
    </tr>
    <tr>
    <td>s4 </td> <td> <input type=checkbox name=num4 id=id4 value="s4" onclick='javascript:check(this)'> </td>
    </tr><tr> <td colspan=2 > <input type=submit value="提交"> </tr>
    </table>
    </form>
    </body>
    </html>