【问题标题】:Unbind hashchange event解除绑定 hashchange 事件
【发布时间】:2016-11-08 12:30:44
【问题描述】:

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

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

像这样解绑:

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

我也试过绑定和解除绑定。 我做错了什么?

谢谢!

【问题讨论】:

    标签: bind unbind hashchange


    【解决方案1】:

    我遇到了类似的问题,但不确定您是否会遇到这种情况 - 更改哈希会触发 onhashchange 事件。

    解决方法是使用历史 API:

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

    这将在不触发 onhashchange 事件的情况下更改哈希。

    【讨论】:

      猜你喜欢
      • 2011-10-13
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多