layui表格更改某列的背景颜色或者字体颜色
0
2877
TSIM
2019/6/26 15:29:11
区分某个字段不同的情况下,显示成的某列的表格颜色不同
做法为在layui表格下layui.use('table', function () 函数里增加done函数
具体代码如下:
[pre]
layui.use('table', function () {
var table = layui.table;
table.init('test', {
toolbar: '#toolbarDemo'
,defaultToolbar: ['filter', 'print', 'exports']
, done: function (res, curr, count) {
console.log(index)
for (var i = 0; i < index; i++) {
$("[data-field='kc" + i + "']").children().each(function () {
if ($(this).text() == '未完成') {
$(this).css({ "background-color": "#ff0000", "color": "#ffffff" });
} else if ($(this).text() == '学习中') {
$(this).css({ "background-color": "#ada548", "color": "#ffffff" });
} else if ($(this).text() == '未参加') {
$(this).css({ "background-color": "#808080", "color": "#ffffff" });
} else if ($(this).text()>0) {
$(this).css({ "background-color": "#439a7a", "color": "#ffffff" });
}
});
}
console.log(JSON.stringify(res))
}
});
})
[/pre]
效果如下:
img[/layedit/img/201906261527486230.png]