【问题标题】:How to activate not default Bootstrap tab from outer page?如何从外部页面激活非默认引导选项卡?
【发布时间】:2012-09-14 07:27:10
【问题描述】:

我有两个链接。首先转到带有默认激活选项卡的页面,然后是第二个链接 - 到第二个选项卡。

我总是激活默认选项卡。

这是我的 js 代码(打开标签 #home):

$('.activate_tab').click(function(e){
  $('#myTab a[href="#profile"]').tab('show');
});

也试过了(什么也没做):

$('.activate_tab').click(function(e){
   e.preventDefault();
   $('#myTab a[href="#profile"]').tab('show');
});

还有我默认的 Bootstrap HTML 代码:

 <ul id="myTab" class="nav nav-tabs">
  <li class="reports active left"><a href="#home" data-toggle="tab" >Details</a></li>
  <li class="reports right not_active" ><a href="#profile" data-toggle="tab">Analytics</a></li>
 </ul>
 ...
 <div class="tab-pane fade in active" id="home">//default
 ...
 <div class="tab-pane fade" id="profile">//not default
 ...
 //link on other page, which should activate default( home )tab
  <a href="/websites/4">http://super.com</a> 
 //link on other page, which should activate not default tab
   <a href="/websites/4" class="activate_tab"><img alt="" height="19" src="http://127.0.0.1:3000/assets/analytics.png" ></a>

我想念什么?

【问题讨论】:

    标签: javascript html twitter-bootstrap


    【解决方案1】:

    我更改了链接:

      <a href="/websites/4#profile" class="activate_tab">aaa</a>
    

    还有我的 JavaScript:

    var activeTab = $('[href=' + location.hash + ']');
    activeTab && activeTab.tab('show');
    
    $('.activate_tab').click(function(e){
    $('#myTab a[href="#profile"]').tab('show');
    });
    

    【讨论】:

      【解决方案2】:

      试试这个

         <div class="tab-pane fade" id="home">//default
       ...
       <div class="tab-pane fade in active" id="profile">//not default
      

      或者你可以尝试你的第二个链接页面

      $('#myTab a:last').tab('show'); // Select last tab
      $('#myTab li:eq(1) a').tab('show'); 
      

      【讨论】:

      • 但是我会将配置文件选项卡设为默认值,是吗?但我不会创建第一个链接 - 打开第一个标签,第二个链接 - 第二个标签。
      • 我会换个问题。像这样的东西。再看一遍。
      猜你喜欢
      • 2016-05-17
      • 2018-01-06
      • 2013-07-23
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 2016-10-08
      • 2014-12-19
      相关资源
      最近更新 更多