如何在第一次加载页面时将活动链接设置为默认值

Amr*_*mra 9 html css hyperlink

当页面第一次加载时,我需要一些帮助来将链接设置为默认活动.

<style type="text/css">
a{
color:black;
}
a:hover{
color:white;
}
a:active{
color:blue;
}
</style>


<div>
<!--I want this fisrt link to be set as active by default-->
<a href="#"/>
<!--I want this one as normal-->
<a href="#"/>
</div>
Run Code Online (Sandbox Code Playgroud)

Dom*_*ger 7

如果您可以将标记更改为:

<div>
<!--I want this first link to be set as active by default-->
<a href="#" id="focusmeplease"/>
<!--I want this one as normal-->
<a href="#"/>
</div>
Run Code Online (Sandbox Code Playgroud)

然后你可以使用这个JavaScript:

document.getElementById('focusmeplease').focus();
Run Code Online (Sandbox Code Playgroud)

将JavaScript附加到页面加载但是你喜欢(我喜欢这种方式,除非你使用jQuery,在这种情况下使用$(document).ready()).