這樣的代碼為什么不可用?不能實(shí)現(xiàn)效果
?var tr=document.getElementsByTagName("tr");?
? ? ? ? for(var i=0;i<tr.length;i++){
?????????????tr[i].onmouseover=function(){
? ? ? ? ? ? ? ? tr[i].style.backgroundColor="#333333";
? ? ? ? ? ? }
? ? ? ? ? ? tr[i].onmouseout=function(){
? ? ? ? ? ? ? ? tr[i].style.backgroundColor="#fff";
? ? ? ? ? ? }
}
2017-08-03
應(yīng)該用this.style.backgroundColor 而不是tr[i].style.backgroundColor
這兩個有什么不同,已經(jīng)alert出來了(前一個是對象,后一個是underfined)