關于this的疑問?菜鳥求解答~~
為什么下面這段代碼中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"; ??????}? } }
2015-06-22
trs[i].onmouseover=function(){
??????????this.style.backgroundColor="#f2f2f2";? ? ? ? ?
??????}
你在這里面分別alert(trs[i]);和alert(this);比較一下