<script><BR>jQuery.fn.tabs = function (control) {<BR> var element = $(this);<BR> var control = $(control);<br><br> element.delegate('li', 'click', function () {<BR> // 遍历选项卡名称<BR> var tabName = $(this).attr('data-tab');<br><br> // 点击选项卡时触发自定义事件<BR> element.trigger('change.tabs', tabName);<BR> });<br><br> // 绑定到自定义事件<BR> element.bind('change.tabs', function (ev, tabName) {<BR> element.find('li').removeClass('active');<BR> element.find('>[data-tab=' + tabName + ']').addClass('active');<BR> });<br><br> element.bind('change.tabs', function (ev, tabName) {<BR> control.find('>[data-tab]').removeClass('active');<BR> control.find('>[data-tab=' + tabName + ']').addClass('active');<BR> });<br><br> // 激活第 1 个选项卡<BR> var firstName = element.find('li:first').attr('data-tab');<BR> element.trigger('change.tabs', firstName);<br><br> return this;<BR>};</script>
jQuery(function ($) {
$('#tabs').tabs('#tabContent');
$('#tab').bind('change.tabs', function (ev, tabName) {
window.loaction.hash = tabName;
});
$(window).bind('hashchange', function () {
var tabName = window.location.hash.slice(1);
$('#tabs').trigger('change.tabs', tabName);
});
});