程序如下:
window.onload = function(){
// 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。
var mytr=document.getElementsByTagName("tr");
for(var i=0;i<mytr.length;i++){
mytr[i].onmouseover=function(){
myte[i].style.backgroundColor="#f2f2f2";}
mytr[i].onmouseout=function(){
myte[i].style.backgroundColor="#fff";}
}
}
var tbody = document.getElementById('table').lastChild;
trs = tbody.getElementsByTagName('tr');
for(var i =1;i<trs.length;i++){
trs[i].onmouseover = function(){
this.style.backgroundColor ="#f2f2f2";
}
trs[i].onmouseout = function(){
this.style.backgroundColor ="#fff";
}
}