我的 JavaScript 中有 2 行代码可以动态更改颜色,一个用于更改表格行的背景颜色,另一个用于更改字体颜色:
rows[i].style.backgroundColor = 'red'
rows[i].style.color = 'white'
当它是超链接时,我需要多行代码来更改字体颜色。我试过了:
rows[i].style.link.color = 'white'
和其他几个变体,但我无法更改链接的字体颜色。有人可以帮忙吗?谢谢。
完整代码:
var INTENDED_MONTH = 7 //August
// INTENDED_MONTH is zero-relative
now = new Date().getDate(),
rows = document.getElementById('scripture').rows;
if (new Date().getMonth() != INTENDED_MONTH) {
// need a value here less than 1, or the box for the first of the month will be in Red
now = 0.5
};
for (var i = 0, rl = rows.length; i < rl; i++) {
var cells = rows[i].childNodes;
for (j = 0, cl = cells.length; j < cl; j++) {
if (cells[j].nodeName == 'TD'
&& cells[j].firstChild.nodeValue != ''
&& cells[j].firstChild.nodeValue == now) {
rows[i].style.backgroundColor = 'red'
rows[i].style.color = 'white'
rows[i].style.a.color = 'white'
$('html,body').delay(500).animate({ scrollTop: rows[i].offsetTop }, 2000);
}
}
}