layui table 最后一行加样式

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>测试 - layui</title>
  <link rel="stylesheet" href="layui/css/layui.css">
  <style>
    .layui-table-box.lastbackground table tbody>tr:nth-last-child(1) {
      background: #b9e7e3;
      color: #fff;
    }
  </style>
</head>

<body>
  <button id="btn" class="layui-button">增加</button>
  <button id="btn2" class="layui-button">取消</button>
  <table id="demo" lay-filter="test"></table>
  </div>
  <script src="layui/layui.js"></script>
  <script>
    var $ = layui.jquery;
    layui.use('table', function () {
      var table = layui.table;
      var $ = layui.jquery;
      $("#btn").click(function () {

        data.push({
          id: 1,
          username: '111'
        })
        table.reload('demo', {
          done: function () {
            $('.layui-table-box').addClass('lastbackground')
          }
        });
      })
      $("#btn2").click(function () {
        data.splice(-1, 1)

        table.reload('demo', {
          done: function () {
            $('.layui-table-box').removeClass('lastbackground')
          }
        });
      })
      var table = layui.table;
      var data = [{
        id: 1,
        username: 'username'
      }]
      //第一个实例
      table.render({
        elem: '#demo'
        , height: 312
        , data: data
        , page: true //开启分页
        , cols: [[ //表头
          { field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left' }
          , { field: 'username', title: '用户名', width: 80 }
          , { field: 'sex', title: '性别', width: 80, sort: true }
          , { field: 'city', title: '城市', width: 80 }
          , { field: 'sign', title: '签名', width: 177 }
          , { field: 'experience', title: '积分', width: 80, sort: true }
          , { field: 'score', title: '评分', width: 80, sort: true }
          , { field: 'classify', title: '职业', width: 80 }
          , { field: 'words', title: '字数', width: 135, sort: true }
        ]]
      });

    });
  </script>
</body>

</html>
posted @ 2022-10-13 18:53  7c89  阅读(215)  评论(0编辑  收藏  举报