• css设置细边框+js控制表格隔行变色


    样式如下(表头为灰色,表格内容颜色为白色和灰色隔行变色,鼠标滑过为深灰色,鼠标离开回复原本颜色)

    <table id="tb1" cellpadding="5" height="20" cellspacing="0">
        <thead>
          <tr id="thColor">
            <td>证书类型</td>
          </tr>
        </thead>
        <tbody id="tb2">
          <tr>
            <td>回忆三部曲</td>
          </tr>
          <tr>
            <td>未麻的部屋</td>
          </tr>
          <tr>
            <td>千年女优</td>
          </tr>
          <tr>
            <td>妄想代理人</td>
          </tr>
          <tr>
            <td>红辣椒</td>
          </tr>
          <tr>
            <td>东京教父</td>
          </tr>
        </tbody>
      </table>
    

      

     <style>
        #tb1 {
           475px;
          text-align: center;
          font-size: 14px;
          background-color: #ccc;
          border-spacing: 1px;
        }
        #thColor {
          background: rgb(245, 245, 245);
          font-weight: bold;
        }
      </style>
    

      

    <script>
        window.onload = function tablecolor() {
          var t_name = document.getElementById("tb2");
          var t_len = t_name.getElementsByTagName("tr");
    
          for (var i = 0; i <= t_len.length; i++) {
            //偶数行时执行
            if (i % 2 == 0) {
              t_len[i].style.backgroundColor = "rgb(255,255,255)"
              //添加鼠标经过事件
              t_len[i].onmouseover = function () {
                this.style.backgroundColor = "rgb(234, 234, 234)"
              }
              //添加鼠标离开事件
              t_len[i].onmouseout = function () {
                this.style.backgroundColor = "rgb(255,255,255)"
              }
            }
            else {
              t_len[i].style.backgroundColor = "rgb(245, 245, 245)";
    
              t_len[i].onmouseover = function () {
                this.style.backgroundColor = "rgb(234, 234, 234)"
              }
              t_len[i].onmouseout = function () {
                this.style.backgroundColor = "rgb(245, 245, 245)"
              }
            }
          }
        }
      </script>
    

      

  • 相关阅读:
    ios添加第三方字体
    IOS 适应各种iphone屏幕尺寸
    sqlite第三方类库FMDB的使用
    IOS--沙盒机制
    用plist建立UITabController
    Xcode7 使用NSURLSession发送HTTP请求报错[转]
    网络开发--NSURLConnection类的简单介绍
    TF-IDF
    《汇编语言》——王爽 第12章 内中断
    操作系统 L4操作系统接口+L5系统调用的实现(网易公开课)
  • 原文地址:https://www.cnblogs.com/yaya-003/p/12180188.html
Copyright © 2020-2023  润新知