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 @   7c89  阅读(224)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
点击右上角即可分享
微信分享提示