html-js案例3

来源:互联网 发布:泰安东华软件股份公司 编辑:程序博客网 时间:2024/06/03 16:47

全选与反选:两种实现方式

<!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>吕老师视频-http://www.tudou.com/home/xuexi158</title>
<script type="text/javascript">

function getAll(){
    //得到同名的控件返回的数组
    var arrs = document.getElementsByName("ids");
    for(var i=0;i<arrs.length;i++){
        arrs[i].checked=true;
    }
}

function getTag(){
    var ars =document.form1.ids;
    for(var j=0;j<ars.length;j++){
        ars[j].checked=true;
    }
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="450" border="1" align="center">
    <tr>
      <td><label>
        <input type="checkbox" name="idall" id="idall" onclick="getTag()" />
      全选</label></td>
      <td>标题</td>
    </tr>
    <tr>
      <td><label>
        <input type="checkbox" name="ids" id="ids" />
      </label></td>
      <td>java</td>
    </tr>
    <tr>
      <td><label>
      <input type="checkbox" name="ids" id="ids" />
      </label></td>
      <td>php</td>
    </tr>
    <tr>
      <td><label>
      <input type="checkbox" name="ids" id="ids" />
      </label></td>
      <td>.net</td>
    </tr>
    <tr>
      <td><label>
      <input type="checkbox" name="ids" id="ids" />
      </label></td>
      <td>C#</td>
    </tr>
  </table>
</form>
</body>
</html>