练习案例_鼠标经过表格行变色

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>鼠标经过表格行变色</title>
    <style type="text/css">

        td{
            border-bottom: 1px solid lightgray;
            width: 100px;
            height: 25px;
        }
        .firstTd{
            width: 30px;
        }
    </style>
    <script type="text/javascript" src="jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            //选中table下面的除了第一行外所有的行
            $("#mailTable tr:not(:eq(0))").mouseenter(function(){
                this.style.backgroundColor="lightgray";
            }).mouseout(function () {
                this.style.backgroundColor="";
            });
        });
    </script>
</head>
<body>


<table id="mailTable" border="0" cellpadding="0" cellspacing="0" style="width: 600px">

    <tr><td class="firstTd"></td><td>收件人</td><td>主题</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>

</table>
</body>
</html>

 

 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title></title>
    <style type="text/css">
        td{
            border-bottom: 1px solid lightgray;
            width: 100px;
            height: 25px;
        }
        .firstTd{
            width: 30px;
        }
    </style>
    <script type="text/javascript">


        window.onload=function(){

            var table = document.getElementById("mailTable");

            var trs = table.getElementsByTagName("tr");
            for(var i=1;i<trs.length;i++){

                var tr = trs.item(i);

                //鼠标进入事件
                tr.οnmοuseοver=function(){

                    this.style.backgroundColor="lightgray";

                }

                //
                tr.οnmοuseοut=function(){

                    this.style.backgroundColor=null;

                }
            }
        }

    </script>
</head>
<body>
    <table id="mailTable" border="0" cellpadding="0" cellspacing="0" style="width: 600px">
        <tr><td class="firstTd"></td><td>收件人</td><td>主题</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
        <tr><td class="firstTd"><input type="checkbox" name="mail" /></td><td>蛋蛋</td><td>。。。</td></tr>
    </table>
</body>
</html>

 

转载于:https://www.cnblogs.com/linyongqin/articles/5572549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值