首页 > 其他分享 >jQuery核心函数之选择器(练习表格隔行变色)

jQuery核心函数之选择器(练习表格隔行变色)

时间:2023-01-11 13:11:51浏览次数:48  
标签:jQuery 删除 color odd 隔行 background data 选择器

视频

行号从0开始。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>01__表格隔行变色</title>
  <style>
    div, span, p {
      width: 140px;
      height: 140px;
      margin: 5px;
      background: #aaa;
      border: #000 1px solid;
      float: left;
      font-size: 17px;
      font-family: Verdana;
    }

    div.mini {
      width: 55px;
      height: 55px;
      background-color: #aaa;
      font-size: 12px;
    }

    div.hide {
      display: none;
    }

    #data {
      width: 600px;
    }

    #data, td, th {
      border-collapse: collapse;
      border: 1px solid #aaaaaa;
    }

    th, td {
      height: 28px;
    }

    #data thead {
      background-color: #333399;
      color: #ffffff;
    }

    .odd {
      background-color: #ccccff;
    }
  </style>
</head>
<body>
<table id="data">
  <thead>
  <tr>
    <th>姓名</th>
    <th>工资</th>
    <th>入职时间</th>
    <th>操作</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>Tom</td>
    <td>$3500</td>
    <td>2010-10-25</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  <tr>
    <td>Mary</td>
    <td>$3400</td>
    <td>2010-12-1</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  <tr>
    <td>King</td>
    <td>$5900</td>
    <td>2009-08-17</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  <tr>
    <td>Scott</td>
    <td>$3800</td>
    <td>2012-11-17</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  <tr>
    <td>Smith</td>
    <td>$3100</td>
    <td>2014-01-27</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  <tr>
    <td>Allen</td>
    <td>$3700</td>
    <td>2011-12-05</td>
    <td><a href="javascript:void(0)">删除</a></td>
  </tr>
  </tbody>
</table>

<script src="jquery-1.10.1.js"></script>
<script>
  // $("#data>tbody>tr:odd").addClass("odd")
  $("#data>tbody>tr:odd").attr('class', 'odd')
</script>
</body>
</html>

结果展示

标签:jQuery,删除,color,odd,隔行,background,data,选择器
From: https://www.cnblogs.com/chuixulvcao/p/17043401.html

相关文章