2010-05-19 118 views
0

我目前有一個選項卡式系統,但它並不完全按照我的需要進行,我希望通過導航到帶#tab2後綴的URL,然後結束它將導航到我的選項卡式頁面存在於URL中的選項卡將是活動的選項卡,但是序列中的第一個選項卡始終處於活動狀態,是否有方法可以首先檢查URL中傳遞的內容,如果存在#tabid,該選項卡的當前標籤?我的JavaScript目前看起來是這樣的,使用jquery的選項卡

$(".tab_content").hide(); //Hide all content 
$("ul.tabNavigation li.shortlist").addClass("active").show(); //Activate first tab (in this case second because of floats) 
$(".tab_content#shortlist").show(); //Show first tab content 

//On Click Event 
$("ul.tabNavigation li").click(function() { 

    $("ul.tabNavigation 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; 
}); 

回答

0

我會建議你使用的jQuery

http://jqueryui.com/demos/tabs/#ajax

內置的標籤UI將藏漢節省您的時間,並做自動選擇藏漢.. 。另外它有一個AJAX選項,因此可以根據請求加載頁面,而無需更改頁面。

1

你可以通過使用window.location.hash得到散列。

因此,像

var hash = window.location.hash; 
if (hash) { 
    $("ul.tabNavigation li").hasClass(hash).click(); 
} 

使用hasClass作爲一種通用的替身,但是你想過濾您LI羽絨。