第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

兩者有什么區(qū)別?求大神指教!

? ?為什么這樣可以,?

? window.onload = function(){

? ? ? ? ? var tr=document.getElementsByTagName("tr");

? ? ? ? ? for(var i= 0;i<tr.length;i++)

? ? ? ? ? {

? ? ? ? ? ? ? bgcChange(tr[i]);

? ? ? ? ? }

? ? ?// 鼠標移動改變背景,可以通過給每行綁定鼠標移上事件和鼠標移除事件來改變所在行背景色。

? ? ? } ? ? ? ??

function bgcChange(obj)

? ? ?{

? ? ? ? obj.onmouseover=function(){

? ? ? ? ? ? obj.style.backgroundColor="#f2f2f2";

? ? ? ? }

? ? ? ? obj.onmouseout=function(){

? ? ? ? ? ? obj.style.backgroundColor="#fff";

? ? ? ? }

}

這樣卻不行?

? window.onload = function(){

? ? var tr=document.getElementsByTagName("tr");

? ? ? ? for(var i= 0;i<tr.length;i++)

? ? ? ? ? {

? ? ? ? ? ? ? tr[i].onmouseover=function(){

? ? ? ? ? ? tr[i].style.backgroundColor="#f2f2f2"; ? ? ? ?}

? ? ? ? tr[i].onmouseout=function(){

? ? ? ? ? ?tr[i].style.backgroundColor="#fff"; ? ? ? ?}

? ? ? ? ? }

? ? ?}


正在回答

2 回答

將? tr[i].style.backgroundColor="#f2f2f2"; 改為?this.style.backgroundColor="#f2f2f2";

0 回復 有任何疑惑可以回復我~

window.onload = function(){
? ?var tr=document.getElementsByTagName("tr");
? ?for(var i= 0;i<tr.length;i++)
? ?{
? ? ? ?tr[i].onmouseover=function(){
? ? ? ? ? ?this.style.backgroundColor="#f2f2f2"; ? ? ? ?}
? ? ? ?tr[i].onmouseout=function(i){
? ? ? ? ? ?this.style.backgroundColor="#fff"; ? ? ? ?}
? ?}
}

這樣就行;

首先

tr[i].onmouseover=function(){

? ? ? ? ? ? tr[i].style.backgroundColor="#f2f2f2"; ? ? ? ?}

這里 function里面的tr[i]因為變量作用域的關系是不存在的,把它換為當前對象this就解決了。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
JavaScript進階篇
  • 參與學習       468767    人
  • 解答問題       22442    個

本課程從如何插入JS代碼開始,帶您進入網(wǎng)頁動態(tài)交互世界

進入課程

兩者有什么區(qū)別?求大神指教!

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號