2013-02-20 66 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