Jquery 和 twitter 引导程序使活动选项卡不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8368429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery and twitter bootstrap make active tab doesnt work
提问by Novo
In twitter bootstrap js tabs i have to add a class "active" to a li element.
在 twitter bootstrap js 选项卡中,我必须向 li 元素添加一个“active”类。
I obtain the hash from the url. I apply the class active to the tab but it doesnt get the focus.
我从 url 获取哈希。我将类 active 应用于选项卡,但它没有得到焦点。
I want to make the second tab active when the url have a certain hash.
当 url 具有特定哈希值时,我想让第二个选项卡处于活动状态。
Source code: http://jsfiddle.net/Chumillas/dU458/#example
采纳答案by Novo
I solved it, i need to set the div of the content of the tab active as well.
我解决了它,我还需要将选项卡内容的 div 设置为活动状态。
回答by Guvener Gokce
Also with latest bootstrap-tab.js, you can use following call to select active tab.
同样使用最新的 bootstrap-tab.js,您可以使用以下调用来选择活动选项卡。
Nav Sample:
导航示例:
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Tab 1</a></li>
<li><a href="#tab2" data-toggle="tab">Tab 2</a></li>
<li><a href="#tab3" data-toggle="tab">Tab 3</a></li>
</ul>
Get object with link and display call:
获取带有链接和显示调用的对象:
$('a[href="#tab2"]').tab('show');
Bests, G.
贝斯特斯,G。
source:Twitter Bootstrap
回答by number5
You can do it like this:
你可以这样做:
$(function (e) {
var parts = decodeURI(e.target).split('#');
$(".tabs").tabs().select(parts[1]);
});
回答by codecypher
To make Bootstrap tabs work, there are two things you have to do to make a tab active:
要使 Bootstrap 选项卡工作,您需要做两件事才能使选项卡处于活动状态:
- Set the li element to active (class="active")
- Set the tab div element to active (class="fade in active")
- 将 li 元素设置为 active (class="active")
- 将选项卡 div 元素设置为活动(class="fade in active")
回答by Jim Jose
Why are u not using the select
method instead of changing the class yourself ??
为什么你不使用该select
方法而不是自己更改类?
check this, Selecting a jQuery Tab using a parameter in the URL
检查这一点,使用 URL 中的参数选择 jQuery 选项卡