我的页面上有这个 Javascript,用于根据内容更改单元格的字体颜色和背景颜色。当上面的所有单元格都包含一个值时,它工作正常。但是,当此列中的上述任何单元格为空白时,整个列都不会应用格式。
有任何想法吗?谢谢。
var allTableCells = document.getElementsByClassName("colhomeaway");
for(var i = 0, max = allTableCells.length; i < max; i++) {
var node = allTableCells[i];
//get the text from the first child node - which should be a text node
var currentText = node.childNodes[0].nodeValue;
//check for contents and assign this table cell's background color accordingly
if (currentText === "H") {
node.style.backgroundColor = "#000099";
node.style.color = "white";
node.style.fontWeight = "bold";}
else
if (currentText === "A"){
node.style.backgroundColor = "#99ffff";
node.style.color = "black";
node.style.fontWeight = "bold";
}
}