window.onload = function() { // 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。 var tr = document.getElementsByTagName("tr"); for (var i = 0; i < tr.length; i++) { tr[i].onmouseover = function() { tr[i].style.backgroundColor = "#f2f2f2"; } tr[i].onmouseout = function() { tr[i].style.backgroundColor = "#fff"; } } } /* window.onload = function() { var tr = document.getElementsByTagName("tr"); for (var i = 0; i < tr.length; i++) { bgcChange(tr[i]); } // 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。 } function bgcChange(obj) { obj.onmouseover = function() { obj.style.backgroundColor = "#f2f2f2"; } obj.onmouseout = function() { obj.style.backgroundColor = "#fff"; } } */
1 回答
已采纳
西兰花伟大炮
TA贡献376条经验 获得超318个赞
<script>
var gettr = document.getElementsByTagName('tr');
//alert(gettr[0]);
for (var i = 0;i < gettr.length;i++){
gettr[i].onmouseover = function(){
this.style.backgroundColor = "blue";
};
gettr[i].onmouseout = function () {
this.style.backgroundColor = "#fff";
}
}
</script>上面的改成this就可以了
添加回答
举报
0/150
提交
取消
