使用 Greasemonkey 根据其内容更改 html table 单元格格式
Use Greasemonkey to change html table cell format based on its content
我无法理解 greasemonkey 脚本。我正在处理一个 html table ,其中第二列有月份数据,例如'April',或 'May'。这是我正在处理的 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>
对于第二个 column/TD 包含 'May' 的所有行,我想使用 greasemonkey 更改该单元格的格式,例如加粗红色文字,黄色背景。这是我到目前为止的代码,但它没有任何效果,我不确定它是否是一个好的起点(我现在只包括背景颜色,走在 运行 之前):
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);
}
实际上我希望 td 从:
<td>May</td>
至:
<td style="background-color: rgb(250, 220, 0); color: rgb(255, 0, 0); font-weight: bold;">May</td>
非常感谢任何建议!谢谢你。 PS 我确实找到了 this 类似的问题,但我不能根据我的情况灵活调整它,这是完全不同的。
rgb(250, 220, 0)
应该是 "rgb(250, 220, 0)"
thetds[j].style.backgroundColor = "rgb(250, 220, 0)";
我无法理解 greasemonkey 脚本。我正在处理一个 html table ,其中第二列有月份数据,例如'April',或 'May'。这是我正在处理的 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>
对于第二个 column/TD 包含 'May' 的所有行,我想使用 greasemonkey 更改该单元格的格式,例如加粗红色文字,黄色背景。这是我到目前为止的代码,但它没有任何效果,我不确定它是否是一个好的起点(我现在只包括背景颜色,走在 运行 之前):
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);
}
实际上我希望 td 从:
<td>May</td>
至:
<td style="background-color: rgb(250, 220, 0); color: rgb(255, 0, 0); font-weight: bold;">May</td>
非常感谢任何建议!谢谢你。 PS 我确实找到了 this 类似的问题,但我不能根据我的情况灵活调整它,这是完全不同的。
rgb(250, 220, 0)
应该是 "rgb(250, 220, 0)"
thetds[j].style.backgroundColor = "rgb(250, 220, 0)";