gpt4 book ai didi

javascript - 单击时更改 anchor 的颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 01:15:49 24 4
gpt4 key购买 nike

新人在这里。我有这 3 个按钮类型的 anchor ,我想在单击它们时更改它们的颜色。我快完成了,但问题是当您单击页面中的其他地方时颜色会发生变化,颜色会恢复为原始颜色。

这是我的代码。我相信要满足要求,需要 javascript,所以我给它一个 javascript 标签。

.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}

.button:active {
background: red;
}

.button:focus {
background: red;
}
<a href="#" class="button">Link 1</a>
<a href="#" class="button">Link 2</a>
<a href="#" class="button">Link 3</a>

最佳答案

将它添加到你的 CSS 中

.button:visited{
background: blue;
}

所有点击的链接都会改变颜色

更多信息在这里 link

.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}

.button:active {
background: red;
}

.button:focus {
background: red;
}

.button:visited {
background: blue;
}
<a href="#/test3" class="button">Link 1</a>
<a href="#/test2" class="button">Link 2</a>
<a href="#/test" class="button">Link 3</a>

关于javascript - 单击时更改 anchor 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50192921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com