我现在做的一个页面是有很多复选框的(动态生成的选项前都复选框)在最下面还有一个复选框旁边有“全选”  当我点击全选的复选框时所有的复选框就都选上了,这样做怎么做啊!又会的么?我不会!但是现在用!那位高手帮帮我!谢谢了!  如果可以告诉我怎么取复选框的值就更好了!呵呵!谢谢大家了!

解决方案 »

  1.   

    <form method="post">
    <div><input type="checkbox" name="chkall" onclick="checkall(this.form)" />选择当前记录</div>
     <input type="checkbox" name="id" value="1" />
    <input type="checkbox" name="id" value="2" />
    <input type="checkbox" name="id" value="3" />
    <input type="checkbox" name="id" value="4" />
    <input type="checkbox" name="id" value="5" />
    </form>  <script type="text/javascript">
        function checkall(f)
        {
           for(var i=0;i<f.elements.length;i++)
           {
             var e=f.elements[i];
             if(e.name!='chkall')
                e.checked=f.chkall.checked;
           }
        }
    </script>
      

  2.   

    <input type="checkbox" name="id" value="1" />
    <input type="checkbox" name="id" value="2" />
    <input type="checkbox" name="id" value="3" />
    <input type="checkbox" name="id" value="4" />
    <input type="checkbox" name="id" value="5" />
    用你代码生成就ok了.加分  ^t^
      

  3.   

    刚写的代码你可以参考一下<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>组成员管理-TEST</title><script type="text/javascript" >function allCheck(oAllChkBox) 

    var oForm = document.getElementById('resForm');
    var oChkBoxes = oForm['item[]'];

    for( i=0;i<oChkBoxes.length;i++ ) 
    {
    oChkBoxes[i].checked = oAllChkBox.checked;
    alert(oChkBoxes[i].value);
    }

    </script>
    </head><body>
    <form id="resForm" name="resForm" method="post" action="" >
      <table width="10%" border="0">
        <tr align="center">
          <td ><input type="checkbox" name="item[]" value="1"></td>
        </tr>
       
     <tr align="center">
          <td width="35%" height="19"><input type="checkbox" name="item[]" value="2"></td>
        </tr>
          <tr align="center">
          <td width="35%" height="19"><input type="checkbox" name="item[]" value="3"></td>
        </tr>
         <tr align="center">
          <td width="35%" height="19"><input type="checkbox" name="item[]" value="4"></td>
        </tr>
      </table>
      <input type="checkbox" name="allChk" onclick="allCheck(this);"> 全选
      </form>
    <br />
    </body>
    </html>
      

  4.   

    <script language="JavaScript">
    <!--
    function chkClk(obj){
    var chks=document.getElementsByName(obj.name);
    //alert(chks.length);
    if(obj.flag){
    for(var i=1;i<chks.length;i++)
    chks[i].checked=obj.checked;
    }
    else{
    for(var i=1;i<chks.length;i++)
    if(chks[i].checked==false){
    chks[0].checked=false;
    break;
    }
    else{
    if(i==chks.length-1) chks[0].checked=true;
    }
    }
    }
    //-->
    </script><input type="checkbox" onclick="chkClk(this)" name="type1" flag="main">typetext
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
    <br><br>
    <input type="checkbox" onclick="chkClk(this)" name="type2" flag="main">typetext
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
    <li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
      

  5.   

    function allchoose()

        var src=document.getElementsByTagName("INPUT"); 
        var check = event.srcElement;
        if(check.checked==false)
        {
          for(var i=0;i <src.length;i++) 
          {
           if(src[i].type=="checkbox")
              src[i].checked=false;  
          } 
        }
        else
        {
          for(var i=0;i <src.length;i++) 
          {
            if(src[i].type=="checkbox")
              src[i].checked=true;  
          } 
         }
    }
    <input type="checkbox" onclick="allchoose()" />全选
                <input type="checkbox">0
                <input type="checkbox">1
                <input type="checkbox">2
                <input type="checkbox">3
                <input type="checkbox">4
                <input type="checkbox">5
                <input type="checkbox">6
                <input type="checkbox">6
                <input type="checkbox">7
                <input type="checkbox">8
                <input type="checkbox">8
                <input type="checkbox">9