是否可以在不导致页面跳转到顶部的情况下从window.location
中删除哈希?我需要能够在不引起任何 skip 的情况下修改哈希.
I have this:
$('<a href="#123">').text('link').click(function(e) {
e.preventDefault();
window.location.hash = this.hash;
}).appendTo('body');
$('<a href="#">').text('unlink').click(function(e) {
e.preventDefault();
window.location.hash = '';
}).appendTo('body');
See live example here: http://jsbin.com/asobi
当用户点击‘link’时,哈希标签被修改,没有任何页面跳转,所以工作正常.
But when the user clicks 'unlink' the has tag is removed and the page scroll-jumps to the top. I need to remove the hash without this side-effect.