如何手动激活Twitter Bootstrap选项卡
使用Twitter Bootstrap的[Tabbable Tabs] [1],它表示:
Using Twitter Bootstrap's [Tabbable Tabs][1], it says to:
通过javascript启用可选项卡的选项卡(每个选项卡需要单独激活)":
"Enable tabbable tabs via javascript (each tab needs to be activated individually)":
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
,然后您可以以多种方式激活各个标签" :
and then you can "activate individual tabs in several ways":
$('#myTab a[href="#profile"]').tab('show'); // Select tab by name
$('#myTab a:first').tab('show'); // Select first tab
$('#myTab a:last').tab('show'); // Select last tab
$('#myTab li:eq(2) a').tab('show'); // Select third tab (0-indexed)
当我单击每个标签并使其#id出现在URL中时,如何分别激活它们?
How could I activate each tab individually when I click in it and have it's #id appear in the URL?
要在网址中添加哈希,可以添加以下内容:
This is to add hash in url you can add this:
$('a').click(function(e){
e.preventDefault();
if(window.location.hash) window.location.hash = '';
window.location.hash = $(e.target).attr('class'); //or id, or other attribute
});
当用户单击"a"标签(或您的标签ID或其他信息)时,然后删除之前的哈希并追加新的哈希. 基本上使用window.location.hash.
when user click on 'a' tag (or your tab id or etc...) then remove previus hash and append new hash. basically use window.location.hash.