layui点击表格单行实现单行改变颜色


		layui.use(['layer', 'form', 'table'], function () {
			var $ = layui.jquery;
			var layer = layui.layer;
			var table = layui.table;
			var form = layui.form;

			var cols = [
				{field: 'id', title: '<spring:message code="Board_Code"/>', align: 'center', templet: function (d) {
						return '<span style="font-size: 20px">'+d.id+'</span>';
					}},
				{field: 'modelname', title: '<spring:message code="DsBoard_modelname"/>', align: 'center', templet: function (d) {
						return '<span style="font-size: 20px">'+d.modelname+'</span>';
					}},
				{field: 'sizex', title: '<spring:message code="DsBoardDesign_boxsizeX"/>', align: 'center', templet: function (d) {
						return '<span style="font-size: 20px">'+d.sizex+'</span>';
					}},
				{field: 'sizey', title: '<spring:message code="DsBoardDesign_boxsizeY"/>', align: 'center', templet: function (d) {
						return '<span style="font-size: 20px">'+d.sizey+'</span>';
					}},
				{field: 'sizez', title: '<spring:message code="DsBoardDesign_boxsizeZ"/>', align: 'center', templet: function (d) {
						return '<span style="font-size: 20px">'+d.sizez+'</span>';
					}},
			];
			let url="${ctxRoot}/dsFront/getBoardList?dsProject.id=${dsBoard.dsProject.id}";
			url=url+"&dsProjectObsid.id=${dsBoard.dsProjectObsid.id}&sysOfficeId=${dsBoard.sysOfficeId}";
			url=url+"&params=${dsBoard.params}&wheresql=AnZhuangTu";
			var insTb = table.render({
				elem: '#dataTable',
				url: url,
				toolbar: false,
				cellMinWidth: 80,
				cols: [cols],
				page: false,
				request: {
					//重点:后台的参数page会冲突
					pageName: 'pageNum',
					limitName: 'pageSize'
				},
				done: function (res, curr, count) {
					$('td').css({'cursor':'pointer'}); //设置成指针放在表格上换成手指
					$('table').width('100%');
					for(var i =0;i<res.data.length;i++){
						if(res.data[i].id==="${dsBoard.id}"){
							$(".layui-table tbody tr").eq(i).attr({ "style": "background:#5FB878;color:#FFFFFF" });
						}
					}
				},
				parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
					return {
						"code": 0, //解析接口状态
						"msg": res.msg, //解析提示文本
						"data": res.result //解析数据列表
					};
				}
			});
			//选中行后改变行背景及字体颜色
			$("body").on('click', '.layui-table-body tr ', function () {

				var data_index = $(this).attr('data-index');//得到当前的tr的index
				$(".layui-table-body tr").attr({ "style": "background:#FFFFFF; color:#666666" });//其他tr恢复颜色
				$(".layui-table-body tr[data-index=" + data_index + "]").attr({ "style": "background:#5FB878;color:#FFFFFF" });//改变当前tr颜色
				
					
			});
		});
	</script>
	<style>
		::-webkit-scrollbar {
			/*隐藏滚轮*/
			display: none;
		}
	</style>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值