2010-03-10 34 views
0

另一頁如何展示與鏈接特定標籤從另一頁jQuery的,以顯示與特定的鏈接標籤從

<a href="index.php?page=home#tab2">Home</a> 

這是JS代碼:

$(document).ready(function() { 

    //When page loads... 
    $(".tab_content").hide(); //Hide all content 
    //$("ul.tabs li:first").addClass("active").show(); //Activate first tab 
    $(".tab_content:first").show(); //Show first tab content 

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

     $("ul.tabs li").removeClass("selected"); //Remove any "active" class 
     $(this).addClass("selected"); //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

您的意思是浴盆 - >標籤? – 2010-03-10 18:03:53

+0

你有沒有試過jQuery標籤UI?可以從http://jqueryui.com/download下載和docs在這裏http://docs.jquery.com/UI/Tabs – 2010-03-10 18:09:56

回答

2

也許這樣的事情?

var openTab = $(location.hash).filter(".tab_content"); 

if(openTab.length){ 
    $("a[href='"+location.hash+"']").click(); 
} 
+0

感謝隊友,完美的工作。 – 2010-03-10 19:29:06

1

如果你正在尋找在頁面加載時使用URL中的散列預先選擇一個標籤,只需使用window.location.hash來存儲當前選定標籤(元素ID?)的標識符,然後在文檔準備就緒時讀取window.location.hash事件觸發,並對其中的任何元素ID作出反應。

相關問題