如何激活不是从外部页面的默认引导标签? [英] How to activate not default Bootstrap tab from outer page?
本文介绍了如何激活不是从外部页面的默认引导标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有哪两个链接。首先进入页面默认激活标签,第二个链接 - 第二个标签。
我总是获得激活的默认选项卡。
这是我的js代码(打开选项卡#home):
$('。activate_tab')。click(function(e){
$('#myTab a [href =#profile]')。tab('show');
}) ;
也尝试过(不做任何事情):
< pre $ $('。activate_tab')。click(function(e){
e.preventDefault();
$('#myTab a [href = #profile]')。tab('show');
});
和我的默认Bootstrap HTML代码:
< ul id =myTabclass =nav nav-tabs>
< li class =reporting right not_active>< a href =#profiledata-toggle =tab> Analytics< / a>< / li>
< / ul>
...
< div class =tab-pane fade in activeid =home> //默认
...
< div class = tab-pane fadeid =profile> //非默认
...
//在其他页面上的链接,它应该激活默认(主页)标签
< a HREF = /网站/ 4 > HTTP://super.com< / A>
//在其他页面上的链接,它应该激活而不是默认标签
< a href =/ websites / 4class =activate_tab>< img alt =height =19 src =http://127.0.0.1:3000/assets/analytics.png>< / a>
我失去了什么人?
解决方案
我改变了我的链接:
< a href =/ websites / 4 #profileclass =activate_tab> aaa< / a>
和我的JavaScript:
var activeTab = $('[href ='+ location.hash +']');
activeTab&& activeTab.tab(节目);
$ b $('。activate_tab')。click(function(e){
$('#myTab a [href =#profile]')。tab('show') ;
});
I have which have two links. First goes to page with default activated tab, and second link - to second tab.
I alway get default tab activated.
Here is my js code(opens tab #home):
$('.activate_tab').click(function(e){
$('#myTab a[href="#profile"]').tab('show');
});
tried also(not doing anything):
$('.activate_tab').click(function(e){
e.preventDefault();
$('#myTab a[href="#profile"]').tab('show');
});
and my default Bootstrap HTML code:
<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>
What I'm missing guys ?
解决方案
I changed my link:
<a href="/websites/4#profile" class="activate_tab">aaa</a>
and my JavaScript:
var activeTab = $('[href=' + location.hash + ']');
activeTab && activeTab.tab('show');
$('.activate_tab').click(function(e){
$('#myTab a[href="#profile"]').tab('show');
});
这篇关于如何激活不是从外部页面的默认引导标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文