哈希更改时如何防止向下滚动页面到主题标签?我尝试了以下方法:
$("#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
,它什么也没做。当它被取消引用时,哈希行为又回来了。如果有人有想法,非常感谢。