设置背景颜色的时候为什么要用this?
var oTr = document.getElementsByTagName("tr"); for(var i=0;i<oTr.length;i++){ oTr[i].onmouseover = function(){ this.style.backgroundColor="#f2f2f2"; } oTr[i].onmouseout = function() { this.style.backgroundColor="#fff"; } }
在上面这代码中,鼠标经过而触发改动背景颜色的函数中,为什么要用“this.style.backgroundColor="#fff";” 我一开始是设想使用“oTr[i].style.backgroundColor="#fff";",结果失败了。
求帮忙告知下失败的原因是什么,谢谢!!!