為什么上面那段代碼不行,而下面的代碼可以,覺得本質(zhì)上沒什么區(qū)別啊,求解
window.onload = function(){
? ? ? ? ? ? ? ? ??
? ? ?// 鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? ? var trs = document.getElementsByTagName("tr");
? ? ? ? for(var i=1;i<trs.length;i++){
? ? ? ? ? ? trs[i].onmouseover = function(){
? ? ? ? ? ? ?this.style.backgroudColor="#ff0000";?
? ? ? ? ? ? }
? ? ? ? ? ? trs[i].onmouseout=function(){
? ? ? ? ? ? ? ?this.style.backgroundColor="#fff";
? ? ? ? ? ? }
? ? ? ? }
}
? ? ?
? ? ?window.onload = function(){
? ? ? ? ? var tr=document.getElementsByTagName("tr");
? ? ? ? ? for(var i= 0;i<tr.length;i++)
? ? ? ? ? {
? ? ? ? ? ? ? bgcChange(tr[i]);
? ? ? ? ? }
? ? ?// 鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? } ? ? ? ??
? ? ?function bgcChange(obj)
? ? ?{
? ? ? ? obj.onmouseover=function(){
? ? ? ? ? ? obj.style.backgroundColor="#ff0000";
? ? ? ? }
? ? ? ? obj.onmouseout=function(){
? ? ? ? ? ? obj.style.backgroundColor="#fff";
? ? ? ? }
}
2016-05-13
是你的拼寫錯誤,第一段代碼的第一個backgroundColor掉了一個“n”