layui 数据表格各行变色属性
时间: 2023-05-26 16:03:44 浏览: 149
layui的表格table选中数据后更改本行的颜色
4星 · 用户满意度95%
layui 数据表格中实现各行变色的属性为 "even" 和 "odd"。
1. "even" 属性用于设定偶数行的样式。
具体代码如下:
```
layui.use('table', function(){
var table = layui.table;
//执行渲染
table.render({
elem: '#demo',
cols: [[ //标题栏
{field: 'name', title: '姓名'},
{field: 'age', title: '年龄'},
{field: 'city', title: '城市'},
{field: 'sign', title: '签名'}
]],
data: [{
"name": "张三",
"age": 20,
"city": "北京",
"sign": "无"
},{
"name": "李四",
"age": 22,
"city": "上海",
"sign": "有"
},{
"name": "王五",
"age": 24,
"city": "广州",
"sign": "爱运动"
},{
"name": "赵六",
"age": 26,
"city": "深圳",
"sign": "技术宅"
}],
even: true //开启偶数行样式
});
});
```
2. "odd" 属性用于设定奇数行的样式。
具体代码如下:
```
layui.use('table', function(){
var table = layui.table;
//执行渲染
table.render({
elem: '#demo',
cols: [[ //标题栏
{field: 'name', title: '姓名'},
{field: 'age', title: '年龄'},
{field: 'city', title: '城市'},
{field: 'sign', title: '签名'}
]],
data: [{
"name": "张三",
"age": 20,
"city": "北京",
"sign": "无"
},{
"name": "李四",
"age": 22,
"city": "上海",
"sign": "有"
},{
"name": "王五",
"age": 24,
"city": "广州",
"sign": "爱运动"
},{
"name": "赵六",
"age": 26,
"city": "深圳",
"sign": "技术宅"
}],
odd: true //开启奇数行样式
});
});
```
阅读全文