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

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

對象的屬性設(shè)置問題

tr是創(chuàng)建的行的對象

1.按照下面代碼,

tr.lastChild.firstChild.onclick="deleteNode(this);";

tr.onmouseover="this.style.background='yellow'";

tr.onmouseout="this.style.background='#fff'";

console.log("打印tr.lastChild.firstChild.onclick內(nèi)容:"+tr.lastChild.firstChild.onclick);

console.log("打印tr.onmouseover內(nèi)容:"+tr.onmouseover);

console.log("打印tr.onmouseout內(nèi)容:"+tr.onmouseout);

通過console.log輸出的都為null,不能正常執(zhí)行,為什么???


2.按照下面代碼

tr.lastChild.firstChild.onclick=function(){

deleteNode(this);

}

tr.onmouseover=function(){

this.style.background="yellow";?

}

tr.onmouseout=function(){

this.style.background="#fff";?

}

通過console.log輸出的都正常,能夠正常執(zhí)行。


3.通過下列代碼

tr.lastChild.firstChild.setAttribute("onclick","deleteNode(this);");

tr.setAttribute("onmouseover","this.style.background='yellow'");

tr.setAttribute("onmouseout","this.style.background='#fff'");

通過console.log輸出的都正常,能夠正常執(zhí)行。

正在回答

1 回答

第一個里面目測是無法將字符串類型的對象隱式轉(zhuǎn)換為事件的類型?;蛘哒f程序并不知道你給OnClick事件賦值的結(jié)果是什么。

第二個,很明顯的通過調(diào)用函數(shù)來執(zhí)行你需要執(zhí)行的刪除操作,沒有問題。

第三個,通過設(shè)置節(jié)點(diǎn)的屬性,類似與你在創(chuàng)建節(jié)點(diǎn)的時候,就已經(jīng)在里面寫入onclick="deleteNode(this)"。

是我的一些看法,希望對你有所幫助。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
JavaScript進(jìn)階篇
  • 參與學(xué)習(xí)       468959    人
  • 解答問題       22582    個

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

進(jìn)入課程

對象的屬性設(shè)置問題

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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