需求:点击layui动态表格的某一行,给这行添加一个背景颜色,用来标识行已被点击
.table-tr-selected-bg { background-color: #6189a7 !important; color: #FFF; }
|
<table id="table1" lay-filter="table1"></table>
|
table.render({ elem: '#table1' , height: 415 , page: false , url: Hussar.ctxPath + "/getData" , cols: [[ {field: 'field0', title: '字段0', align: "center",}, , {field: 'field1', title: '字段1', align: "center"} , {field: 'field2', title: '字段2', align: "center",} ]] , done(res) { $("div[lay-id='table1'] div.layui-table-box div.layui-table-body tr:eq(0)").addClass('table-tr-selected-bg') } });
table.on('row(table1)', function (obj) { $('.table-tr-selected-bg').removeClass('table-tr-selected-bg'); $(obj.tr).addClass('table-tr-selected-bg'); });
|