如何将链接状态设置为在用户访问另一个页面之前保持

How would I set the link state to remain until the user visits another page?

本文关键字:另一个 访问 用户 链接 状态 设置      更新时间:2023-09-26

我想知道如何使导航栏上的按钮保持活动状态(在本例中为不同的背景颜色),而用户仍留在该页面上,在访问另一个页面时切换,以便他们始终知道自己的位置?

这是我不知道的简单事情,还是需要一些JavaScript之类的东西?

感谢您的阅读!

你是说这种效果吗?

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="https://code.jquery.com/jquery-2.2.3.min.js" charset="utf-8"></script>
        <style>
            .title{
                float: left;
                background-color: #51D7FF;
                margin-right: 10px;
                width: 80px;
                text-align: center;
            }
            .current{
                background: #4DFFE4;
            }
        </style>
        <script>
            $(document).ready(function(){
                var myDate = new Date();
                $('.title1').addClass('current');
                $('.title').click(function(){
                    $(this).addClass('current');
                    $(this).siblings().removeClass('current');
                }); 
            });
        </script>
    </head>
    <body>
        <div class="title title1">title1</div>
        <div class="title title2">title2</div>
        <div class="title title3">title3</div>
    </body>
</html>