Use onhashchange and hash-free refresh the page

1, an example: http://blog.csdn.net/aitangyong/article/details/46455627 

 

2, own examples

// onhashchange hash can monitor changes 
window.onhashchange = function () {
     var hash = the window.location.hash;
     var ID = the parseInt (hash.substr (. 1));   // hash value # 0, the second to be intercepted two values, and converted to an integer 
    showPage (id);
};
// Home display (The following method is a method, respectively, button clicks) 
function homePage (the above mentioned id) {
    showPage(id);
}
// first page 
function firstPage (ID) {
    showPage(id);
}
// display page 
function showPage (the above mentioned id) {
    $("div[id!="+id+"]").hide();
    $("#"+id).show();
    the window.location.hash = ID;   // the hash changed, the browser automatically generates a history 
}

 

Guess you like

Origin www.cnblogs.com/masha2017/p/11094728.html