http://jsfiddle.net/Mrbaseball34/CQXBx/3/
HTML:
<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
<li class="active">
<a href="#tab1">Profile Settings</a>
</li>
<li>
<a href="#tab2">Email & Password</a>
</li>
<li>
<a href="#tab3">Phone Numbers</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<span>Tab1</span>
</div> <!-- tab1 -->
<div class="tab-pane active" id="tab2">
<span>Tab2</span>
</div> <!-- tab2 -->
<div class="tab-pane active" id="tab3">
<span>Tab3</span>
</div> <!-- tab3 -->
</div>
</div>
Javascript:
$(document).ready(function () {
var tabs = $('.tabbable'),
tab_a_selector = '.nav-tabs a';
tabs.find( tab_a_selector ).click(function(e){
e.preventDefault();
$(this).tab('show');
var state = {},
// Get the id of this tab widget.
id = $(this).closest('.tabbable').attr('id'),
// Get the index of this tab.
idx = $(this).parent().prevAll().length;
// Set the state!
state[id] = idx;
$.bbq.pushState(state);
});
$(window).on('hashchange', function (e) {
tabs.each(function () {
var idx = $.bbq.getState(this.id, true) || 0;
$(this).find(tab_a_selector).eq(idx).triggerHandler('click');
});
})
.trigger('hashchange');
});
CSS:
body { background: #fff; }
我似乎无法让 Bootstrap Tabbable (tabs-left) 与 BBQ 的 hashchange 一起正常工作。
谁能看到我做错了什么?