简体   繁体   English

使用Greasemonkey根据其内容更改html表格单元格格式

[英]Use Greasemonkey to change html table cell format based on its content

I'm way out of my depth with a greasemonkey script. 我不喜欢使用油腻的猴子脚本。 I'm dealing with an html table where the second column has month data in, eg 'April', or 'May'. 我正在处理一个html表,其中第二列包含月份数据,例如'April'或'May'。 Here's a simplified version of the html I'm dealing with: 这是我正在处理的html的简化版本:

<html>
    <body>
        <form>
            <table class="gridtable">
                <tbody>
                    <tr class="header"></tr>
                    <tr>
                        <td>blah</td>
                        <td>April</td>
                        <td>blah</td>
                    </tr>
                    <tr>
                        <td>blah</td>
                        <td>May</td>
                        <td>blah</td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>

For all rows where the 2nd column/TD contains 'May', I want to use greasemonkey to change the formatting of that cell, eg to bold red text, with a yellow background. 对于第二列/ TD包含“五月”的所有行,我想使用滑脂粉更改该单元格的格式,例如,以黄色背景更改为粗体红色文本。 Here's the code I have so far, but it's not having any effect, and I'm not sure if it's a good starting point (I've only included background color for now, walk before run): 这是我到目前为止的代码,但是没有任何效果,我不确定这是否是一个很好的起点(我现在仅包括背景色,请在跑步前先走一下):

var thetds = document.getElementsByTagName('td');
for (var j = 0; j < thetds.length; j++) {
if (thetds[j].innerHTML == "May") 
    thetds[j].style.backgroundColor = rgb(250, 220, 0);
}

Effectively I want the td to turn from: 实际上,我想让td转为:

<td>May</td>

to: 至:

<td style="background-color: rgb(250, 220, 0); color: rgb(255, 0, 0); font-weight: bold;">May</td>

Any advice greatly appreciated! 任何建议,不胜感激! Thank you. 谢谢。 PS I did find this similar question but I can't flex it to my situation, it is quite different. 附言:我确实找到类似的问题,但是我无法根据自己的情况提出,这是完全不同的。

rgb(250, 220, 0) should be "rgb(250, 220, 0)" rgb(250, 220, 0)应该是"rgb(250, 220, 0)"

thetds[j].style.backgroundColor = "rgb(250, 220, 0)";

example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM