0

I'm brazilian so, first, sorry for any English error.

My problem is this: I want a menu that clear the previous visited links (turning them to normal again), but keeping the link the current visited link as a:visited in css.

I have found a way to make this. But the problem is it is not working!! This is the code that I have:

< ul id="menuTop">
    < li id="menu-link-1">@Html.ActionLink("Home", "Index", null, null, new { id = "link-1-visited" })</li>
    < li id="menu-link-2">@Html.ActionLink("Produtos", "Products", null, null, new { id = "link-2-visited" })</li>

    < li id="menu-link-3">@Html.ActionLink("Fale Conosco", "ContactUs", null, null, new { id = "link-3-visited" })</li>

    < li id="menu-link-4">@Html.ActionLink("Quem Somos", "AboutUs", null, null, new { id = "link-4-visited" })</li>
< /ul>

This is my buttons, and the code to make them "visited" is that:

  $(document).ready(function() {
        $('#link-1-visited').click(function()
        {
            $("#menu-link-1").removeAttr("menu-link-1");
            $(this).addClass('link-1-visited');
            window.alert("test 1 !!");
        });

        $('#link-2-visited').click(function()
        {
            $(this).addClass('link-1-visited');
            window.alert("test 2 !!");
        });

        $('#link-3-visited').click(function()
        {
            $(this).addClass('link-1-visited');
            window.alert("test 3 !!");
        });

        $('#link-4-visited').click(function()
        {
            $(this).addClass('link-1-visited');
            window.alert("test 4 !!");
        });
    });

The problem is my code in menu-link-1 is not working. I want to remove the ul and li css and add class "link-1-visited" to it.

Do you have any ideas about how can I do that?

4

1 回答 1

0

不幸的是,无法从JavaScript访问它,您只能显示它..

浏览器根据仅它知道的数据库条目指示已访问链接,然后使用特定浏览器配置中指定的默认颜色。

如果您只想要视觉呈现的结果,那么最快的方法是使用 CSS 计数器。

CSS:

body{
    counter-reset: visited_counter;
}

a:visited{
    counter-increment: visited_counter;
}

#results:before{
    content:counter(visited_counter);
}

这将在 id 为“results”的元素之前添加已访问链接的数量。

或者

不过,这个jQuery 解决方案效果很好。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            var normalColor = $('a:link').css('color');
            $('a:visited').css('color', normalColor);
        });
    </script>
于 2013-07-15T06:04:16.037 回答