繁体   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