加载页面后如何触发鼠标悬停?

时间:2013-08-08 07:52:09

标签: jquery html

我希望在页面完全加载后触发鼠标悬停在超链接上。我不想使用活动和访问它。(由于某些编程原因)。

我的意思是说在页面加载后,超链接应该处于悬停颜色。

我正在尝试此代码,但没有取得任何成功。

<html>
<head>
    <style type="text/css">
    a:hover {
    color: #00a000;
    }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

        <script type="text/javascript">
            jQuery(document).ready(function(){                          
                jQuery("#myLink").trigger('mousehover');            
            });
        </script>   
</head>
<body>
<a id="myLink" href="www.google.com">google</a>
</body>
</html>

1 个答案:

答案 0 :(得分:3)

当没有鼠标时,试图触发mouseevent,我只想添加一个类。我假设你有一些CSS已经解决了这个问题。这是更清洁的IMO,并没有滥用'鼠标悬停'。

jQuery(document).ready(function(){                          
    jQuery("#myLink").addClass('hover');            
});
相关问题