单击其他超链接时更改超链接颜色

use*_*327 6 html css href

当点击其他链接时,如何将超链接颜色更改回原始颜色?超链接的目标是同一页面.

请查看这个 DEMO

从上面的例子中你可以看到,当点击苹果然后点击葡萄/香蕉..两者都变成相同的颜色,因为(访问过).单击任何链接时如何使其只有1种颜色(绿色)

web*_*pur 2

您可以使用以下方法执行此操作jQuery

$('body a:link').click(function()
{
	$('body a').removeClass('active');
	$(this).addClass('active');	 
});
Run Code Online (Sandbox Code Playgroud)
a:link {
    color: blue;
}

/* visited link */
a.active {
    color: green;
}

/* mouse over link */
a:hover {
    color: red;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)