0

First of all, my coding skills are very basic so please bear with me.

I am making a website for an art exhibition which has many people contributing.

I have a page called profiles.html which contains all of the profile of the people who have contributed.

Each profile is contented within a DIV called profiles along with an anchor tag of the persons name.

If people go to the website www.example.com/profiles.html they will see all of the profiles.

However when they go to
www.example.com/profiles.html#example.name they will only see the profile of that person.

I have looked around the internet to try and find answers but I have not found any.

UPDATE:

A follow up question. Is it possible to show/ load extra content in the profiles.html#examplename that would not be seen in profiles.html

4

1 回答 1

0

假设你有:

  • class="profile"每个配置文件的包装器
  • 以及每个 pofile 包装器上的 id,与您的哈希匹配(如“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();
}
于 2013-02-20T20:13:56.633 回答