如何在页面首次加载时将活动链接设置为默认值 [英] How to set a active link as default when page first time load

查看:138
本文介绍了如何在页面首次加载时将活动链接设置为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助才能在首次加载网页时将链接设置为默认活动。

I need some help to set a link as active as default when the page load the first time.

<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>


推荐答案

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

If you can change your markup to this:

<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>

然后您可以使用此JavaScript:

Then you can use this JavaScript:

document.getElementById('focusmeplease').focus();

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

Attach that JavaScript to page load however you like (I like this way, unless you're using jQuery, in which case use $(document).ready()).

这篇关于如何在页面首次加载时将活动链接设置为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆