我有兩行代碼在我的JavaScript來動態改變顏色,一個更改錶行的背景顏色和其他更改字體顏色:代碼來改變字體顏色的文本是一個鏈接
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);
}
}
}
你不是應該使用CSS呢? – 0x499602D2
正在JavaScript內使用css代碼。這一切都有效,我所需要的只是改變鏈接文本顏色的最終命令。你知道那是什麼嗎? –
我的意思是你不應該在'style'標籤中處理CSS代碼嗎?建議分開管理CSS/JS/HTML。 – 0x499602D2