鼠標(biāo)移動(dòng)變色的問(wèn)題
這是我自己的代碼語(yǔ)言實(shí)現(xiàn)鼠標(biāo)變色功能,期間也參考了正解和他人的代碼都沒(méi)有看到變色效果,是代碼問(wèn)題嗎?還是瀏覽器問(wèn)題?
function?onload()?{ ????var?tbody?=?document.getElementById('table').lastChild; ????var?trlist?=?tbody.getElementsByTagName('tr'); ????for?(var?i?=?1;?i?<?trlist.length;?i++)?{ ????????trlist[i].onmouseover?=?function?()?{ ????????????this.style.backgroundColor?=?"#f2f2f2"; ????????} ????????trlist[i].onmouseout?=?function?()?{ ????????????this.style.backgroundColor?=?"#fff"; ????????} ????} }
2016-05-09
你這只是定義了一個(gè)名為onload的函數(shù)。window.onload = function(){}是頁(yè)面加載完后將執(zhí)行這里的匿名函數(shù)。
2016-05-05
i=0,應(yīng)該是從0開(kāi)始的,如果前面有window.onload的話,把function onload去掉試試,試了一下是可以的。
2016-05-05
window.onload = function(){ ? ? ? ? ? ? ?
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過(guò)給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來(lái)改變所在行背景色。
? ? ? ? ?var tdarr = document.getElementsByTagName("tr");
? ? ? ? ? for (var i=0; i< tdarr.length;i++){
? ? ? ? ? ? ? ? tdarr[i].onmouseover = function(){
? ? ? ? ? ? ? ? ? ? this.style.backgroundColor ="#f2f2f2";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? tdarr[i].onmouseout = function(){
? ? ? ? ? ? ? ? ? ? this.style.backgroundColor ="#fff";
? ? ? ? ? ? ? ? }
? ? ? ?} ? ? ? ?
}
這事我的最后一個(gè)練習(xí)題的代碼,你看下吧