<script>
function sel()
{
o=document.getElementsByName("chkbox")
for(i=0;i<o.length;i++)
o[i].checked=event.srcElement.checked
}
</script>
<input type="checkbox" onclick='sel()'>圈选<br>
<input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox">

解决方案 »

  1.   

    <script>
    s=true
    function sel()
    {
    o=document.getElementsByName("chkbox")
    for(i=0;i<o.length;i++)
    o[i].checked=s
    s=!s
    }
    </script>
    <input type="button" onclick='sel()' value=圈选>
    <input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox">
      

  2.   

    <script>
    s=true
    function sel()
    {
    o=document.getElementsByTagName("INPUT")
    for(i=0;i<o.length;i++)
    if(o[i].type && o[i].type=="checkbox") o[i].checked=s
    s=!s
    }
    </script>
    <input type="button" onclick='sel()' value=圈选>
    <input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox"><input type="checkbox" name="chkbox">
      

  3.   

    <input type=checkbox>1
    <input type=checkbox>1
    <input type=checkbox>1
    <input type=checkbox>1
    <br>
    <input type="button" value="全选" onclick="doCheckBox(1)">
    <input type="button" value="全不选" onclick="doCheckBox(2)">
    <input type="button" value="反选" onclick="doCheckBox(3)">
    <script>
    function doCheckBox(iType)
    {
    //1:全选;2:全不选;3:反选;
    for(iIndex=0;iIndex<document.all.length;iIndex++)
    {
    if(document.all(iIndex).type=="checkbox")
    {
    switch(iType)
    {
    case 1:document.all(iIndex).checked=true;break;
    case 2:document.all(iIndex).checked=false;break;
    case 3:{if(document.all(iIndex).checked==true){document.all(iIndex).checked=false;}else{document.all(iIndex).checked=true;}}break;
    }
    }
    }
    }
    </script>
      

  4.   

    function SelectAll(yn)
    {
        var L
    L = document.getElementsByName("ProductID").length;
    for(var i=0;i<L;i++)
    {
        if(yn=="y")
    {
        document.all.ProductID[i].checked="checked";
    }
    else
    {
        document.all.ProductID[i].checked="";
    }
    }
    }<input type="checkbos" name="ProductID"><input type="checkbos" name="ProductID">
    <input type="checkbos" name="ProductID"><input type="checkbos" name="ProductID">
    <input type="checkbos" name="ProductID"><input type="checkbos" name="ProductID">
    <span style="cursor:hand" onclick="javascript:SelectAll('y')">全选</span> / <span style="cursor:hand" onclick="javascript:SelectAll('n')">全不选</span>
      

  5.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>例子</title>
    </head><body>
    <form>
    <input type="button" value="全选中" onClick="SelectAll(true);">
    <input type="button" value="全不选" onClick="SelectAll(false);">
    <input type="button" value="反向选" onClick="AgainstSelect();">
    <input type="checkbox" name="selected_id[]">
    <input type="checkbox" name="selected_id[]">
    <input type="checkbox" name="selected_id[]">
    <input type="checkbox" name="selected_id[]">
    </form>
    </body>
    <script language="JavaScript">
    <!--
    var MyObject=window.document.forms[0];function SelectAll(varFlag){
    for(var i=0;i<MyObject.elements.length;i++){
    if(MyObject.elements[i].type=="checkbox"){
    MyObject.elements[i].checked=varFlag
    }
    }
    }function AgainstSelect(){
    for(var i=0;i<MyObject.elements.length;i++){
    if(MyObject.elements[i].type=="checkbox"){
    MyObject.elements[i].checked=!MyObject.elements[i].checked
    }
    }
    }
    -->
    </script>
    </html>
      

  6.   

    <form name=hrong>
    <input type=checkbox name=All onclick="checkAll('mm')">全选<br/>
    <input type=checkbox name=mm onclick="checkItem('All')"><br/>
    <input type=checkbox name=mm onclick="checkItem('All')"><br/>
    <input type=checkbox name=mm onclick="checkItem('All')"><br/>
    <input type=checkbox name=mm onclick="checkItem('All')"><br/>
    <input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
    <input type=checkbox name=All2 onclick="checkAll('mm2')">全选<br/>
    <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
    <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
    <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
    <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
    <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/></form><SCRIPT LANGUAGE="JavaScript">
    function checkAll(str)
    {
      var a = document.getElementsByName(str);
      var n = a.length;
      for (var i=0; i<n; i++)
      a[i].checked = window.event.srcElement.checked;
    }
    function checkItem(str)
    {
      var e = window.event.srcElement;
      var all = eval("document.hrong."+ str);
      if (e.checked)
      {
        var a = document.getElementsByName(e.name);
        all.checked = true;
        for (var i=0; i<a.length; i++)
        {
          if (!a[i].checked){ all.checked = false; break;}
        }
      }
      else all.checked = false;
    }
    </SCRIPT>