zoukankan      html  css  js  c++  java
  • 表格隔行变色效果,鼠标悬浮高亮显示

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>


    <style>
    * {
    margin: 0;
    padding: 0;
    }
    table {
    margin: 150px auto;
    500px;
    border: 1px solid #000;
    }
    tr {
    height: 40px;
    }
    td {
    border: 1px solid #000;
    line-height: 40px;
    text-align: center;
    }

    </style>

    <script>
    window.onload = function () {
    var tbody = document.getElementsByTagName("tbody")[0];
    var trArr = tbody.getElementsByTagName("tr");


    for(var i=0;i<trArr.length;i++){

    if(i%2===0){
    trArr[i].style.backgroundColor = "#BEBEBE";
    }else{
    trArr[i].style.backgroundColor = "#D0B8AD"

    }
    var color = "";
    trArr[i].onmouseover = function () {
    color = this.style.backgroundColor;
    this.style.backgroundColor = "#76B481";

    }
    trArr[i].onmouseout = function () {

    this.style.backgroundColor = color;
    }
    }


    }
    </script>
    </head>
    <body>



    <table>
    <caption>表格一:XXXXXXXX</caption>

    <thead>
    <tr>
    <td>编号</td>
    <td>姓名</td>
    <td>年龄</td>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>111</td>
    <td>姓名</td>
    <td>13</td>
    </tr>
    <tr>
    <td>222</td>
    <td>姓名</td>
    <td>35</td>
    </tr>
    <tr>
    <td>333</td>
    <td>姓名</td>
    <td>346</td>
    </tr>
    <tr>
    <td>444</td>
    <td>姓名</td>
    <td>23</td>
    </tr>
    <tr>
    <td>555</td>
    <td>姓名</td>
    <td>23</td>
    </tr>
    <tr>
    <td>666</td>
    <td>姓名</td>
    <td>12</td>
    </tr>
    <tr>
    <td>777</td>
    <td>姓名</td>
    <td>32</td>
    </tr>
    <tr>
    <td>888</td>
    <td>姓名</td>
    <td>23</td>
    </tr>
    <tr>
    <td>999</td>
    <td>姓名</td>
    <td>14</td>
    </tr>

    </tbody>

    </table>
    </body>
    </html>
  • 相关阅读:
    数据库主体拥有数据库角色,无法删除
    document.documentElement.scrollTop Google Chrome 不 兼容
    js 获取 焦点的元素 兼容 ie 火狐 safari 等
    LNMP分离安装
    WEB开发模式调整
    牛出租车司机(转)
    nginx优化(转)
    pam_mysql编译安装(Ubuntu10.10)
    CruiseControl.NET使用
    nginx学习资料收集(补充中....)
  • 原文地址:https://www.cnblogs.com/summer0319/p/6059805.html
Copyright © 2011-2022 走看看