如何手动激活Twitter Bootstrap选项卡 [英] How to activate Twitter Bootstrap Tabs manually

查看:102
本文介绍了如何手动激活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.

这篇关于如何手动激活Twitter Bootstrap选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆