25.表格全选——案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
        table{
            border:1px solid;
            margin:auto;
            width:500px;
        }
        td,th{
            text-align:center;
            border:1px solid;
        }
        div{
            text-align:center;
            margin:50px;
        }
        .out{
            background-color:white;
        }
        .over{
            background-color:pink;
        }
    </style>
    <script>
        window.onload = function(){
            document.getElementById("selectAll").onclick = function(){
                var cbs = document.getElementsByName("cd");
                for(var i=0;i<cbs.length;i++){
                    cbs[i].checked = true;
                }
            }
            document.getElementById("unSelectAll").onclick = function(){
                var cbs = document.getElementsByName("cd");
                for(var i=0;i<cbs.length;i++){
                    cbs[i].checked = false;
                }
            }
            document.getElementById("selectRev").onclick = function(){
                var cbs = document.getElementsByName("cd");
                for(var i=0;i<cbs.length;i++){
                    cbs[i].checked = !cbs[i].checked;
                }
            }
            document.getElementById("firstCd").onclick = function(){
                var cbs = document.getElementsByName("cd");
                for(var i=0;i<cbs.length;i++){
                    cbs[i].checked = this.checked;
                }
            }
            var trs = document.getElementsByTagName("tr");
            for(var i=0;i<trs.length;i++){
                trs[i].onmouseover = function(){
                    this.className = "over";
                }
                trs[i].onmouseout = function(){
                    this.className = "out";
                }
            }
        }
    </script>
<body>
<div>
    <input type="text" id="id" placeholder="请输入编号">
    <input type="text" id="name" placeholder="请输入姓名">
    <input type="text" id="gender" placeholder="请输入性别">
    <input type="button" id="add" value="添加">
</div>
<table id="table">
    <caption>学生信息表</caption>
    <tr class="tr" >
        <th><input type="checkbox"id="firstCd" name="cd"></th>
        <th>编号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>操作</th>
    </tr>
    <tr class="tr">
        <td><input type="checkbox"  name="cd"></td>
        <td>1</td>
        <td>令狐冲</td>
        <td>男</td>
        <td><a href="javascript:void(0)" onclick="delTr(this)">删除</a></td>
    </tr>
    <tr class="tr">
        <td><input type="checkbox" name="cd"></td>
        <td>2</td>
        <td>任我行</td>
        <td>男</td>
        <td><a href="javascript:void(0)" onclick="delTr(this)">删除</a></td>
    </tr>
    <tr class="tr">
        <td><input type="checkbox" name="cd"></td>
        <td>3</td>
        <td>岳不群</td>
        <td>?</td>
        <td><a href="javascript:void(0)" onclick="delTr(this)">删除</a></td>
    </tr>
</table>
    <div>
        <input type="button" id="selectAll" value="全选">
        <input type="button" id="unSelectAll" value="全不选">
        <input type="button" id="selectRev" value="反选">
    </div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值