【问题标题】:Prevent class remove on hash change防止在哈希更改时删除类
【发布时间】:2014-02-28 16:47:27
【问题描述】:

我有 jquery 将活动类分配给我的主要和上下文导航。

<script type="text/javascript">
        $(document).ready(function () {
            var url = window.location;
            $('ul.nav a').filter(function () {
                return this.href == url;
            }).parent().addClass('active-dropdown').parent().parent().addClass('active');
            var url = window.location;
            $('ul.contextual-navigation a').filter(function () {
                return this.href == url;
            }).parent().addClass('contextual-active');
            $('<i class="icon-hand-right"></i>').prependTo('.contextual-active'); 
        });

    </script>

例如,当 url 为 /about/index.html 时,类按预期分配,但当它更改为 /about/index.html#team 时,活动类被删除。当#hashtag 在该页面中处于活动状态时,是否有办法将活动类分配给主导航和上下文导航。

【问题讨论】:

    标签: jquery twitter-bootstrap tabs


    【解决方案1】:

    此处不使用 window.location.href,而是使用 window.location.pathname。 你可以看到 Link anatomy

    了解有关 window.location 的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 2019-12-11
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多