可能重复:
Modifying document.location.hash without page scrolling
如何在哈希发生变化时阻止页面向下滚动到主题标签?我尝试了以下方法:
$("#button_bar a").click(function(event) {
event.preventDefault(); //This was to prevent the hash scroll down behavior
window.location.hash = this.hash; //This makes scroll down to the hash again
$(window).hashchange( function(){ //this recognizes if the hash has changed
recognizeHashTag(); //this identifies the hashtag and fires an ajax call
});
});
问题是当我引用window.location.hash = this.hash
时,它什么也没做。当它没有引用时,哈希行为再次出现。
如果有人有一个想法,非常感谢。