根据标题文本更改列的背景颜色 [英] Change background color of column based on header text

查看:93
本文介绍了根据标题文本更改列的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:如果标题td中有特定文本,则需要更改整个列的背景颜色.我尝试过几种不走运的方法.

Problem: I need to change an entire column's background color if specific text is in the header td. I've tried several different ways with no luck.

我尝试使用以下方法获取标题:

I tried getting the header with:

$('td:contains(Sun)').addClass('.weekend');

即使改变颜色也不起作用.那就是我目前所处的位置.

That didn't work to even change the colors. That's where I'm currently stuck.

推荐答案

小提琴

var txt = 'Header 2';
var column = $('table tr th').filter(function() {
    return $(this).text() === txt;
}).index();

if(column > -1) {
    $('table tr').each(function() {
        $(this).find('td').eq(column).css('background-color', '#eee');
    });
}

这篇关于根据标题文本更改列的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆