我想防止在hashchange事件中跳转到锚点。我可以想出如何在点击链接时禁用此行为。但不幸的是,相同的代码不适用于hashchange事件。下面是我的代码:
$('.parent').on('click', 'a', function(e) {
e.preventDefault(); // this works perfectly fine
});
$(window).on('hashchange', function(e) {
e.preventDefault(); // doesn't work
});发布于 2021-04-09 02:48:01
根据the documentation的说法,hashchange事件是不可取消的,而a click event是可以取消的。
https://stackoverflow.com/questions/67010001
复制相似问题