[英]How to show the id of the button when hover over it
Using the following code I can change the name of the button when user hovers over it.使用以下代码,当用户将鼠标悬停在按钮上时,我可以更改按钮的名称。 Is there a way to change the button's name with its id when user hovers over it (using JavaScript)?
当用户将鼠标悬停在按钮上时(使用 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>
You can use attr(id)
.您可以使用
attr(id)
。 See the documentation for further information.有关详细信息,请参阅文档。
.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>
Here's one that changes things back...这是一个可以改变事情的...
onmouseover="this.innerHTML=this.id;"
onmouseout="this.id=this.innerHTML; this.innerHTML='old name';"
Just add these events to the button.只需将这些事件添加到按钮。
Quite easy actually...其实很简单...
onmouseover="this.innerHTML=this.id;" onmouseover="this.innerHTML=this.id;"
Just add this event to the button.只需将此事件添加到按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.