2013-02-20 65 views
0

首先,我的編碼技巧是非常基本的,所以請耐心等待。只顯示特定的div與錨點

我正在製作一個有很多人蔘與的藝術展覽的網站。

我有一個名爲profiles.html的頁面,其中包含所有貢獻者的個人資料。

每個配置文件都在DIV中稱爲配置文件以及人名的錨標籤。

如果有人前往網站 www.example.com/profiles.html 他們會看到所有的配置文件。

然而,當他們去
www.example.com/profiles.html#example.name 他們將只能看到人的輪廓。

我看了看周圍的互聯網,試圖找到答案,但我還沒有找到任何。

更新:

後續問題。是否可以顯示/在profiles.html#範例名稱負荷額外的內容,不會在profiles.html

回答

0

可以看出假設你有:

  • class="profile"一個包裝周圍的每個配置文件
  • 而每個pofile包裝標識,符合哈希(如「example.name」)

那麼我相信你想要的東西是這樣的:

// On page load 
$(document).ready(function(){ 

    // React to clicks on anchors 
    window.onhashchange = hashChanged; 

    // React to directly type urls 
    hashChanged(); 

}); 

// When the URL hash (#something) changes 
function hashChanged() { 
    // hide all profiles 
    $('.profile').hide(); 
    // get the current hasj minus '#' 
    var profileId = window.location.hash.substr(1); 
    // show only the appropriate profile 
    $('#' + profileId).show(); 
} 
+0

「example.name」,由於「。」而不起作用,請將其刪除,並且完美地工作。感謝您的快速和質量幫助。 – Simon 2013-02-20 20:32:20

+0

我很高興它幫助! – bfavaretto 2013-02-20 20:45:38

+0

跟進問題。 是否有可能在profiles.html#examplename中顯示/加載額外的內容,這些內容在profiles.html中不會出現 – Simon 2013-02-20 20:57:44