簡體   English   中英

當 hover 超過按鈕時如何顯示按鈕的 ID

[英]How to show the id of the button when hover over it

使用以下代碼,當用戶將鼠標懸停在按鈕上時,我可以更改按鈕的名稱。 當用戶將鼠標懸停在按鈕上時(使用 JavaScript),有沒有辦法用它的 id 更改按鈕的名稱?

 .button:hover span { display: none }.button:hover:before { content: "New name"; }.button:hover { background-color: #aaaaaa; }
 <button class="button" id="some_id"> <span>old name</span> </button>

您可以使用attr(id) 有關詳細信息,請參閱文檔

 .button:hover span { display: none }.button:hover:before { content: attr(id); }.button:hover { background-color: #aaaaaa; }
 <button class="button" id="some_id"> <span>old name</span> </button>

這是一個可以改變事情的...

onmouseover="this.innerHTML=this.id;"

onmouseout="this.id=this.innerHTML; this.innerHTML='old name';"

只需將這些事件添加到按鈕。

其實很簡單...

onmouseover="this.innerHTML=this.id;"

只需將此事件添加到按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM