2011-03-30 72 views

回答

4

據例如,你可以用這種方式modifi它:

$(function() { 
    $(".tab_content").hide(); //Hide all content 
    //On Click Event (left standart) 
    $("ul.tabs li").click(function() { 

     $("ul.tabs li").removeClass("active"); //Remove any "active" class 
     $(this).addClass("active"); //Add "active" class to selected tab 
     $(".tab_content").hide(); //Hide all tab content 
     var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content 
     $(activeTab).fadeIn(); //Fade in the active ID content 
     return false; 
    }); 


    // here we are looking for our tab header 
    hash = window.location.hash; 
    elements = $('a[href="' + hash + '"]'); 
    if (elements.length === 0) { 
     $("ul.tabs li:first").addClass("active").show(); //Activate first tab 
     $(".tab_content:first").show(); //Show first tab content 
    } else { 
     elements.click(); 
    } 
}); 

Working example is here。要小心 - 散列硬編碼那裏,因爲我不知道如何通過它來測試框架:(

+0

工作就像一個魅力! – 2011-06-30 22:18:13

+0

幫助我謝謝! – Heihachi 2013-03-26 10:24:35

0

是的,你可以做到這一點。您將需要一些代碼來抓取url並觸發適當的選項卡。

或者你可以檢查出jQuery的工具選項卡(http://flowplayer.org/tools/demos/tabs/) 或jQuery UI的標籤(http://jqueryui.com/demos/tabs/)

這些都具有該功能(和一噸的其他選項)已經內置

2

我沒有測試這一點,但你應該能夠從URL獲得哈希:

var hash= window.location.hash; 

然後用請求的哈希鏈接抓取鏈接元素,並模擬點擊它

$("a[href='"+hash+"']").click();