给layui的列设置背景色,以及字体颜色

本文介绍如何使用layui框架实现表格中的字体颜色及背景颜色设置,并探讨了合并单元格的方法及其可能遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、字体颜色设置,最简单的办法

   style:'color: #f6d06'

,{field: 'rongQiJiHuaCha',title: '容器',align:'center', width:'60',style:'color: #f67d06;', totalRow: true}

2、给列设置背景色

 
  done: function (res, curr, count) {
           var that = this.elem.next();
           res.data.forEach(function (item, index) {
            // 所需的条件
              if(item.shouldMonth > 0){
            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='threeMonth']").css("background-color", "#1E9FFF");
            }
           });}
 
 
 

表格渲染代码

/* 疑问:想在最后加一列备注,合并4行,但是失败,样式会乱,如果加在供应商名称后,就没问题*/
            table.render({
                elem: '#tableList'
                ,url:'${pageContext.request.contextPath }/kanban/piLiangChaiXiangKanBan.do'
                ,id :'contentTable'
                ,totalRow: true //开启合计行
                ,page : false
                ,height : 600
                ,cols: [
                    [
                        {title:'序号',width: 50,type:'numbers', align:'center', rowspan: 4}
                        ,{field: 'customer_name', title:'供应商名称', width:'150', align:'center', rowspan: 4, totalRowText: '合计:'}
                        ,{title:'倒箱品库存现况', align:'center', colspan: 14}
                        ,{title:'倒箱品作业现况', align:'center', colspan: 6}

                    ],
                    [
                        {title:'库存', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'日发货计划', align:'center', colspan: 8}
                        ,{title:'下趟数', align:'center', colspan: 4}
                        ,{title:'今日计划', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'完成数', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'未完成', align:'center', rowspan: 2, colspan: 2}
                    ],
                    [
                        {title:'计划总数', align:'center', colspan: 2}
                        ,{title:'已发货', align:'center', colspan: 2}
                        ,{title:'未发货', align:'center', colspan: 2}
                        ,{title:'差额', align:'center', colspan: 2}
                        ,{title:'计划总数', align:'center', colspan: 2}
                        ,{title:'差额', align:'center', colspan: 2}
                    ],
                    [
                        {field: 'wuLiaoKuCun',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiKuCun',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoJiHuaFaHuo',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiJiHuaFaHuo',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoYiFa',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiYiFa',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoWeiFa',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiWeiFa',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoJiHuaCha',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiJiHuaCha',title: '容器',align:'center', width:'60',style:'color: #f67d06;', totalRow: true}
                        ,{field: 'wuLiaoXiaGeJiHua',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiXiaGeJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoXiaGeJiHuaCha',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiXiaGeJiHuaCha',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiJiHua',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiChaiJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiYiZuo',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiChaiYiZuo',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiWeiZuo',title: '物料',align:'center', width:'80',style:'color: #f67d06;', totalRow: true}
                        ,{field: 'rongQiChaiWeiZuo',title: '容器',align:'center', width:'60',style:'color: #f67d06;', totalRow: true}
                    ]
                ]
                ,done : function(res, curr, count){
                    $('th').css({
                        'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                    });
                    var divArr = $(".layui-table-total div.layui-table-cell");
                    $.each(divArr,function (index,item) {
                        var _div = $(item);
                        var content = _div.html();
                        content = content.replace(".00","");
                        _div.html(content);
                    });
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        // 所需的条件
                        if(item.wuLiaoJiHuaCha > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoJiHuaCha']").css("background-color", "#1E9FFF");
                        }
                        if(item.wuLiaoChaiWeiZuo > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoChaiWeiZuo']").css("background-color", "#1E9FFF");
                        }
                    });
                }
            });

效果截图

### LeetCode 'Two Sum' 问题的 C++ 解决方案 #### 暴力解法 (Brute Force Approach) 暴力方法通过双重循环遍历数组中的每一对元素,检查它们之和是否等于目标值 `target`。这种方法的时间复杂度为 \(O(n^2)\),空间复杂度为 \(O(1)\)[^1]。 ```cpp class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { for(int i = 0; i < nums.size(); i++) { for(int j = i + 1; j < nums.size(); j++) { if(nums[j] == target - nums[i]) { return {i, j}; } } } return {-1, -1}; } }; ``` --- #### 哈希表优化解法 (Hash Table Optimization) 为了提高效率,可以使用哈希表存储已经访问过的数值及其索引位置。这样可以在一次遍历中完成查找操作,时间复杂度降低到 \(O(n)\),而空间复杂度增加至 \(O(n)\)[^3]。 ```cpp #include <unordered_map> using namespace std; class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> hashTable; for(int i = 0; i < nums.size(); ++i){ int complement = target - nums[i]; if(hashTable.find(complement) != hashTable.end()){ return {hashTable[complement], i}; } hashTable[nums[i]] = i; } return {}; } }; ``` 此代码利用了一个无序映射 (`unordered_map`) 来记录已扫描的数字以及其对应的下标。每次迭代都会计算当前数字所需的补数,并检查该补数是否已经在哈希表中存在。 --- #### 排序数组上的双指针技术 (Two Pointers Technique on Sorted Array) 如果输入数组已经是有序的,则可以通过双指针的方法进一步减少内存消耗并提升性能。初始时设置左指针指向第一个元素,右指针指向最后一个元素;随后逐步调整两个指针的位置直到找到满足条件的一对数字或者确认不存在这样的组合[^2]。 ```cpp class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { int l = 0, r = numbers.size() - 1; while(l < r){ if(numbers[l] + numbers[r] > target) r--; else if(numbers[l] + numbers[r] < target) l++; else return {l+1, r+1}; } return {}; } }; ``` 注意这里返回的结果是从 1 开始计数的索引值而不是默认从零开始的标准 C++ 数组索引。 --- #### 总结 上述三种算法分别代表了不同的思路和技术应用方向: - **暴力枚举**适合理解基础逻辑但不适用于大规模数据集; - **哈希表辅助**提供了更高效的解决方案,在实际开发场景中最常用; - **双指针策略**则针对特定情况(即预排序列表)进行了特殊优化处理。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值