单击其他链接后,如何将我的超链接颜色更改回原始颜色?超链接的目标是在同一页面上。
请检查此 DEMO
从上面的示例中,您可以看到,当单击“苹果”然后单击“葡萄/香蕉”时,两者都变为相同的颜色,因为(访问)。单击任何链接时如何仅使其变为一种颜色(绿色)
最佳答案
您可以使用jQuery
完成此操作
$('body a:link').click(function()
{
$('body a').removeClass('active');
$(this).addClass('active');
});
a:link {
color: blue;
}
/* visited link */
a.active {
color: green;
}
/* mouse over link */
a:hover {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="fruit" href="#apple">apple</a></span>
<a class="fruit" href="#grape">grape</a></span>
<a class="fruit" href="#banana">banana</a></span>
<div style="height:500px"></div>
<a name="apple"> apple here</a>
<a name="grape"> grape here</a>
<a name="banana"> banana here</a>