设置layui动态表格某一行的背景色

以下示例设置动态表格某一行的数据

ea.table.render({

init: init,

toolbar: ['refresh', 'delete','add'],

cols: [[

{type: 'checkbox'},

{field: 'id', title: 'id'},

{field: 'cate.title', title: '分类'},

{field: 'image', title: '缩略图', templet: ea.table.image},

{field: 'name', title: '姓名'},

{field: 'phone', title: '电话'},

{field: 'license_number', title: '执业证号'},

{field: 'level', title: '等级'},

{field: 'province', title: '省'},

{field: 'city', title: '市'},

{field: 'good_sector', title: '擅长领域'},

{field: 'remark', title: '备注', templet: ea.table.text},

{field: 'create_time', title: '添加时间'},

{field: 'status', title: '状态', templet: ea.table.switch},

{field: 'price', title: '价格'},

{width: 250, title: '操作', templet: ea.table.tool},

]],

done: function (res, curr, count) {

console.log(res); //打印数据

console.log(curr);//打印当前行数

console.log(count); //数据总条数

// 官方介绍 https://www.layui.com/doc/modules/table.html#templet

res.data.forEach(function (item, index) { //循环数据

if (item.id == 1) { //当数据id为1时

var tr = $(".layui-table").find("tbody tr[data-index='" + index + "']"); //查找某一行的数据

tr.css("background-color", "#98FB98"); //标记该行的背景色

// 给1-0-9列添加样式

tr.find(".laytable-cell-1-0-9").css("color","red"); //标记该行某一列的颜色

}

});

}

});

相关推荐
铁皮饭盒1 分钟前
第2课:5分钟!用 Trae AI 生成你的第一个后端服务(Bunjs + Elysia)
前端·后端·全栈
之歆31 分钟前
DAY13_CSS3进阶完全指南 —— 背景、边框、文本、渐变、滤镜与 Web 字体(下)
前端·css·css3
剑神一笑1 小时前
CSS 阴影生成器:从单层到多层叠加的艺术
前端·css·css3
lljss20201 小时前
1. NameServer 域名服务器---NS
linux·服务器·前端
anOnion2 小时前
构建无障碍组件之Tooltip Pattern
前端·html·交互设计
陈随易2 小时前
为什么今天还会有新语言?MoonBit 想解决什么问题?
前端·后端·程序员
西洼工作室2 小时前
unipp+vue3+python h5+app极验验证码集成全流程解析
前端·uni-app·全栈·极验
ZC跨境爬虫2 小时前
跟着 MDN 学 HTML day_15:(媒体缓冲、拖动与时间范围控制)
前端·笔记·ui·html·edge浏览器·媒体
李白的天不白2 小时前
webpack 与 webpack-cli 版本匹配问题
前端·webpack·node.js