添加onmouseover和onmouseout事件相關問題
trs[i].onmouseover = function(){
this.style.backgroundColor ="#f2f2f2";
}?
trs[i].onmouseout = function(){
this.style.backgroundColor ="#fff";
}
為什么其中的this換成trs[i]就不能實現????
trs[i].onmouseover = function(){
this.style.backgroundColor ="#f2f2f2";
}?
trs[i].onmouseout = function(){
this.style.backgroundColor ="#fff";
}
為什么其中的this換成trs[i]就不能實現????
2014-12-24
舉報
2014-12-24
因為你在函數中沒有傳遞過去,你是在trs[i]元素上綁定的事件,所以在事件函數中必須知道對象是誰,this就是本身的對象