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