<!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>
<script language=javascript> 
function selectBox(selectType){
    if (typeof selectType =="object")testselect()
    if (typeof selectType =="string"){
     var ws= selectType=='all'?1:0
     setselect(ws)
     testselect()
    }
}
    
function testselect(){
    var checkboxis = document.getElementsByName("checkbox");
    var list = [];
    for (var i=0; i<checkboxis.length; i++)
       if (checkboxis[i].checked)
        list[list.length] = checkboxis[i].value;
    for (var j=0;j<list.length;j++){
               alert( list[j]);
    }
}function setselect(ws){
    var checkboxis = document.getElementsByName("checkbox");
    for (var i=0; i<checkboxis.length; i++)
        checkboxis[i].checked = ws;
}onload=function(){
    var checkboxis = document.getElementsByName("checkbox");
    for (var i=0; i<checkboxis.length; i++){
checkboxis[i].onclick=function(){selectBox(this)}
    }
}
</script> 
</head><body>
  <form id="form1" name="form1" method="post" action="">
    <table width="120" border="1">
      <tr>
        <td colspan="2">
            <input type="button" name="all" value="全选" onclick="selectBox('all')"/>
            <input type="button" name="reverse" value="取消" onclick="selectBox('reverse')"/>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          checkbox1<input type="checkbox" name="checkbox" value="checkbox1" />
        </td>
      </tr>
      <tr>
        <td width="110">
            checkbox2<input type="checkbox" name="checkbox" value="checkbox2" />
        </td>
      </tr>
      <tr>
        <td colspan="2">
           checkbox3<input name="checkbox" type="checkbox" id="checkbox" value="checkbox3" />
        </td>
      </tr>
    </table>
  </form></body>
</html>

解决方案 »

  1.   


    <!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>
    <script language=javascript> 
    function selectBox(selectType){
        if (typeof selectType =="object")testselect()
        if (typeof selectType =="string"){
         var ws= selectType=='all'?1:0
         setselect(ws)
         testselect()
        }
    }
        
    function testselect(){
        var checkboxis = document.getElementsByName("checkbox");
        var list = [];
        for (var i=0; i<checkboxis.length; i++)
           if (checkboxis[i].checked)
            list[list.length] = checkboxis[i].value;
        for (var j=0;j<list.length;j++){
                   alert( list[j]);
        }
    }function setselect(ws){
        var checkboxis = document.getElementsByName("checkbox");
        for (var i=0; i<checkboxis.length; i++)
            checkboxis[i].checked = ws;
    }onload=function(){
        var checkboxis = document.getElementsByName("checkbox");
        for (var i=0; i<checkboxis.length; i++){
    checkboxis[i].onclick=function(){selectBox(this)}
        }
    }
    </script> 
    </head><body>
      <form id="form1" name="form1" method="post" action="">
        <table width="120" border="1">
          <tr>
            <td colspan="2">
                <input type="button" name="all" value="全选" onclick="selectBox('all')"/>
                <input type="button" name="reverse" value="取消" onclick="selectBox('reverse')"/>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              checkbox1<input type="checkbox" name="checkbox" value="checkbox1" />
            </td>
          </tr>
          <tr>
            <td width="110">
                checkbox2<input type="checkbox" name="checkbox" value="checkbox2" />
            </td>
          </tr>
          <tr>
            <td colspan="2">
               checkbox3<input name="checkbox" type="checkbox" id="checkbox" value="checkbox3" />
            </td>
          </tr>
        </table>
      </form></body>
    </html>