【问题标题】:Set Active Tab in Tab Nav coming from another link Bootstrap在来自另一个链接 Bootstrap 的选项卡导航中设置活动选项卡
【发布时间】:2015-10-12 11:00:41
【问题描述】:

编辑:这不是我的主导航栏,它是表单内的导航栏。此 Tab Nav 仅存在于 resources-terms.html

我有一个位于resources-terms.html 的标签导航

<div class="tabbable">
  <ul class="nav nav-tabs" id="tab_bar">
      <li class="active"><a href="#tab1" data-toggle="tab"><i class="glyphicon glyphicon-pencil"></i>AU and NZ Terms & Conditions</a></li>
      <li><a href="#tab2" data-toggle="tab"><i class="glyphicon glyphicon-user"></i> UK Terms & Conditions </a></li>
   </ul>

    <div class="tab-content">
        <div class="tab-pane active" id="tab1"> Content 1</div>
        <div class="tab-pane active" id="tab2"> Content 2</div>
    </div>
</div>

假设我正在查看index.html,我需要直接转到resources-terms.html 的链接格式应该是什么?tab2 已经选中并处于活动状态?

我尝试了&lt;a href="resources-terms.html#tab2&gt;Link&lt;/a&gt;",但没有成功。

【问题讨论】:

    标签: html twitter-bootstrap hyperlink tabs


    【解决方案1】:

    您正在寻找的内容(通过location.hash 值导航到特定选项卡)不会自行发生。您需要在 resources-terms.html 文件中处理此问题。

    页面完全加载后,读取hash并将对应的tab设置为active,如下图:

    $(document).ready(function(){
        if (location.hash) {
            $('a[href=' + location.hash + ']').tab('show');
        }
    });
    

    【讨论】:

    • 我编辑了我的问题,这似乎令人困惑,因为有人可能会认为我的标签导航栏是我的主导航栏,而不是我的主导航栏。根据您的代码,它应该如何知道应该将哪个选项卡设置为活动状态?至于我的问题,如果我来自 index.html,我应该输入什么链接才能直接将选项卡 2 设为活动状态?
    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    相关资源
    最近更新 更多