偏爱花开的声音
2015-06-21 15:39
为什么下面这段代码中onmouseover()函数中这一句:
this.style.backgroundColor="#f2f2f2";
写成:
trs[i].style.backgroundColor="#f2f2f2";
结果就不对了呢?!谢谢大家~~
window.onload = function(){ // 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。 var trs = document.getElementsByTagName("tr"); for(var i = 0;i<trs.length;i++){ trs[i].onmouseover=function(){ this.style.backgroundColor="#f2f2f2"; } trs[i].onmouseout=function(){ this.style.backgroundColor="#fff"; } } }
trs[i].onmouseover=function(){
this.style.backgroundColor="#f2f2f2";
}
你在这里面分别alert(trs[i]);和alert(this);比较一下
JavaScript进阶篇
468746 学习 · 22132 问题
相似问题