我想你應該遵循Modifying document.location.hash without page scrolling
對於簡單的解決方案,你需要做一些小把戲,比如 - 預先準備一些文本的哈希值,使其不再引用現有的元素!
您可以從下面的代碼片段中找到可能的提示,它是從以上鍊接的答案之一複製而來的。
$(function(){
//This emulates a click on the correct button on page load
if(document.location.hash){
$("#buttons li a").removeClass('selected');
s=$(document.location.hash.replace("btn_","")).addClass('selected').attr("href").replace("javascript:","");
eval(s);
}
//Click a button to change the hash
$("#buttons li a").click(function(){
$("#buttons li a").removeClass('selected');
$(this).addClass('selected');
document.location.hash="btn_"+$(this).attr("id")
//return false;
});
});
[修改document.location.hash無頁滾動]的可能重複(http://stackoverflow.com/questions/1489624/modifying-document-location-hash-without-page-scrolling) –