<input type=checkbox name=mm value=a onclick="cc(this)"><br>
<input type=checkbox name=mm value=b onclick="cc(this)"><br>
<input type=checkbox name=mm value=c onclick="cc(this)"><br>
<input type=checkbox name=mm value=d onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br>
<input type=checkbox name=mm value=e onclick="cc(this)"><br><script language=Javascript>
function cc(e)
{
  var a = document.getElementsByName("mm");
  var n = 0;
  for (var i=0; i<a.length; i++)
  {
     if (a[i].checked) n++
     if (n > 6)
     {
       alert("你只能选 6 个");
       e.checked = false;
       return;
     }
  }
}
</script>

解决方案 »

  1.   

    梅花雨看到你,就有希望了,
    你能不能去回答我的另一个问题?
    http://expert.csdn.net/Expert/topic/1274/1274183.xml?temp=.1227838
      

  2.   

    <input type=checkbox name=mm value=a onclick="cc(this)"><br>
    <input type=checkbox name=mm value=b onclick="cc(this)"><br>
    <input type=checkbox name=mm value=c onclick="cc(this)"><br>
    <input type=checkbox name=mm value=d onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <script>
    var n=0;
    function cc(obj)
    {
    if(obj.checked)
    n++;
    else
    n--; if (n > 6)
         {
           alert("你只能选 6 个");
           obj.checked = false;
       n--;
           return;
         }
    }
    </script>
    要是checkbox多的话这样会好点吧
      

  3.   

    <form name="form1">
    <input type=checkbox name=mm value=a onclick="cc(this)"><br>
    <input type=checkbox name=mm value=b onclick="cc(this)"><br>
    <input type=checkbox name=mm value=c onclick="cc(this)"><br>
    <input type=checkbox name=mm value=d onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=checkbox name=mm value=e onclick="cc(this)"><br>
    <input type=button value=提交 onclick="checkForm()">
    </form>
    <script>
    var n=0;
    function cc(obj)
    {
    if(obj.checked)
    n++;
    else
    n--; if (n > 6)
         {
           alert("你只能选 6 个");
           obj.checked = false;
       n--;
           return;
         }
    }
    function checkForm()
    {
    if (n==0){
    alert("请选择一项!");
    return false;
    }
    else
    document.all("form1").submit();
    }
    </script>