我想你应该遵循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) –