這樣為什么沒有作用
indow.onload = function(){
? ? ? ? ? ? ? ? ? var tr=document.getElementsByTagName("tr");
? ? ? ? ? ? ? ? ? for(var i=0;i<tr.length;i++)
? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ?//change(tr[i]);
? ? ? ? ? ? ? ? ? ? ?tr[i].onmouseover= function(){
? ? ? ? ? ? ? ? ? ? ? ? ? tr[i].style.backgroundColor="blue";
? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ?tr[i].onmouseout=function(){
? ? ? ? ? ? ? ? ? ? ? ? ?tr[i].style.backgroundColor="red";
? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ??
}
2014-12-18
tr[i].style.backgroundColor="blue"; ?改成 ? this.style.backgroundColor="blue";
2014-12-18
我做服務端的,沒深入過javascript,偶爾接觸一下前端,也寫出過像這樣的代碼,感覺是OK的但是沒用!?。。∧銌枮槭裁次乙膊恢?,我記得解決方法是把onmouseout和onmouseover 對應的方法里面的‘tr[i]’改成‘this’,據(jù)說是作用域的錯誤。