把每个checkbox的id起的有规则一些,像2维数组那样
如: c00 c01 c02 .....
     c10 c11 .......
     ......
然后就可以在一个循环里处理了,如:
for(i=0;i<4;i++)
{
document.getElementByID("c0"+i).checked;
}

解决方案 »

  1.   

    遍历document.getElementsByName("checkboxName")或者document.getElementsByTagName("INPUT")
    然后判断type是否是checkbox,参考
    dhtml手册http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asphttp://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getelementsbytagname.asp
      

  2.   

    <script language="javascript">
    <!--
      function fnc1()
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox') document.all(i).checked = true;
        }
      }  function fnc2(strid)
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = true;
        }
      }  function fnc3(obj)
      {
        var o = obj.parentElement.parentElement.getElementsByTagName('INPUT');
        for(var i=0;i<o.length;i++)
        {
          o[i].checked = true;
        }
      }
    //-->
    </script><table>
    <tr>
    <td id=1>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
    <td id=2>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
    <td id=3>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
    <td id=4>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    </table>
    <p>全选<input type=checkbox onclick="fnc1();"></p>
      

  3.   

    呵呵,稍微完善了一下,这样就能反复点击,看到效果~~~<script language="javascript">
    <!--
      function fnc1(obj)
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox') document.all(i).checked = obj.checked;
        }
      }  function fnc2(strid,obj)
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = obj.checked;
        }
      }  function fnc3(obj)
      {
        var o = obj.parentElement.parentElement.getElementsByTagName('INPUT');
        for(var i=0;i<o.length;i++)
        {
          o[i].checked = obj.checked;
        }
      }
    //-->
    </script><table>
    <tr>
    <td id=1>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
    <td id=2>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
    <td id=3>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
    <td id=4>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    <tr>
    <td id=1>行<input type=checkbox onclick="fnc3(this);">
    <td id=2><input type=checkbox>
    <td id=3><input type=checkbox>
    <td id=4><input type=checkbox>
    </tr>
    </table>
    <p>全选<input type=checkbox onclick="fnc1(this);"></p>