简体   繁体   English

鼠标悬停时更改字体颜色,然后单击javascript或html

[英]Changing font color on mouseover and click javascript or html

I have a couple of html links, that I have onmouseover and onmouseout set to change colors, what I want to be able to do is when I click one of the links, the links is set to a certain color and mouse over effect no longer works on the clicked link but does on the others. 我有几个html链接,我将onmouseover和onmouseout设置为更改颜色,我想要做的是单击链接之一时,链接设置为某种颜色,并且鼠标悬停效果不再在点击的链接上有效,但在其他链接上有效。 these links activate javascript functions but do not direct to another webpage. 这些链接可激活javascript功能,但不会定向到另一个网页。

Any ideas how I could do this? 有什么想法可以做到吗?

<a href="javascript:void(0)" id="paint" onclick="slidedown(this)"  style="color:#FFF" onmouseover="this.style.color = '#FF6600'" onmouseout="this.style.color = '#FFF'"><font style="font-family:pirulen; font-size:12px; margin-left:10px; "><b>Painting</b></font></a>

this is one of my links as you can see I have onmouseover and onmouseout set. 这是我的链接之一,您可以看到我设置了onmouseover和onmouseout设置。

Use this CSS to get the hover effect 使用此CSS获得悬停效果

a{
    color:#fff;
}
a:hover{
    color:#FF6600;
}
a.selected,a.selected:hover{
    color:#000000;
}

Now, on your function slidedown you can add a class .selected when you click on the link. 现在,在功能下拉列表中,您可以添加单击链接时选择的类。

this.className = this.className + " selected";

您可以在单击链接时将某些样式类添加到链接中,这会覆盖其他样式并抑制鼠标悬停样式。

将鼠标悬停在一个类上,并创建一个单击按钮,它会在单击时更改链接类,这样,悬停将不会应用于单击的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM