取消绑定hashchange事件

问题描述 投票:1回答:1

是否可以取消绑定hashchange事件?我这样绑定它:

jQuery(window).on('hashchange', function() {
                alert("ok");
            });

和解除绑定像这样:

jQuery(window).off('hashchange');

我也尝试过bind和unbind。我究竟做错了什么?

谢谢!

bind unbind hashchange
1个回答
0
投票

我有类似的问题,但不确定它是否适合你 - 更改哈希触发了onhashchange事件。

解决方法是使用历史API:

history.replaceState(null, null, document.location.pathname + '#' + hash);

这将更改哈希而不会触发onhashchange事件。

© www.soinside.com 2019 - 2024. All rights reserved.