jQuery を使用したくない場合は、JavaScript のコードを次に示します。
http://jsfiddle.net/u72yF/3/
color = function() {
var table = document.getElementById('myTable');
var trList = table.getElementsByTagName('tr');
// index of the status column
var index = -1;
for (var i = 0; i < trList.length; i++) {
var tdList = trList[i].getElementsByTagName('td');
if (index < 0) {
// we need to find out the status column index first
for (var j = 0; j < tdList.length; j++) {
if (tdList[j].id == 'statusColumn') {
index = j;
break;
}
}
}
if (tdList[index].innerHTML.trim() == 'Late') {
// for constant coloring
trList[i].style.background = '#FFD7D7';
// for on hover coloring
//trList[i].onmouseover = function() {
// this.style.background = '#FFD7D7';
//}
//trList[i].onmouseout = function() {
// this.style.background = '';
//}
}
}
}
私は、コードがどの列がステータスであるかを知らないと仮定したため、検出が含まれています(ID「statusColumn」による)。「Late」文字列はこの列でのみ検索され、他の列は無視されます。
色付けによって、一定の色付け (私が示しました) ではなくホバーの色付けを意味する場合は、これを実装する下部のコメントを削除します。