鼠标经过改变背景颜色问题
window.onload = function(){
var tableRows=document.getElementsByTagName("tr");
for(var i=0;i<tableRows.length;i++){
tableRows[i].onmouseover=function(){
tableRows[i].style.backgroundColor="yellow";
}
tableRows[i].onmouseout=function(){
tableRows[i].style.backgroundColor="#CCC";
}
}
}为什么这种设置颜色时,总对初始那两行报Cannot read property 'style' of undefined错误,然后只在新增加一行的上面生效。然后我改成图片那种就没有问题了。我感觉这是差不多的啊。

我的添加代码:
