js-改变表格背景颜色 - 帘

时间:2024-03-11 16:27:32

js-改变表格背景颜色

// 表格背景颜色变换
function changeBg() {
var tableBg = document.getElementById("allH_Table");
for (i = 0; i < tableBg.rows.length; i++) {
if (tableBg.rows[i].tagName == "TR") {
tableBg.rows[i].className
= (i % 2 == 1 ? "list_tr1" : "list_tr2");
}
else {
break;
}
}
}
// 根据移动到不同的行改变改行的背景颜色
function currentRow() {
var pclass = "";
var obj = document.getElementById("allH_Table");
for ( var i = 0; i < obj.rows.length; i++) {
obj.rows[i].onmouseover
= function() {
pclass
= this.className;
this.className = "action";
};
obj.rows[i].onmouseout
= function() {
this.className = pclass;
};

}

}
.list_tr1{ background-color:#cccccc;}
.list_tr2
{ background-color:#ffffff;}
.action
{background-color:#00ff00;}