亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

對象的屬性設置問題

tr是創建的行的對象

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內容:"+tr.lastChild.firstChild.onclick);

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

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

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


2.按照下面代碼

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

deleteNode(this);

}

tr.onmouseover=function(){

this.style.background="yellow";?

}

tr.onmouseout=function(){

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

}

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


3.通過下列代碼

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

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

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

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

正在回答

1 回答

第一個里面目測是無法將字符串類型的對象隱式轉換為事件的類型。或者說程序并不知道你給OnClick事件賦值的結果是什么。

第二個,很明顯的通過調用函數來執行你需要執行的刪除操作,沒有問題。

第三個,通過設置節點的屬性,類似與你在創建節點的時候,就已經在里面寫入onclick="deleteNode(this)"。

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

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

舉報

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

本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界

進入課程

對象的屬性設置問題

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

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號