【问题标题】:$(document).off() doesn't remove any events from the document$(document).off() 不会从文档中删除任何事件
【发布时间】:2016-08-03 17:55:42
【问题描述】:

我正在运行这个 jQuery 的 sn-p 以从基于 ui-router 的 Angular 应用程序中删除所有事件侦听器,但它似乎没有做任何事情?是不是违规操作?

$rootScope
    .$on('$stateChangeStart', 
        function(event, toState, toParams, fromState, fromParams){ 
            console.log("Going to remove event listeners"); // this fires
            $(document).off();
    });

【问题讨论】:

  • 我也尝试在 chrome 开发控制台中运行它,没有错误。我仍然看到元素选项卡下的所有事件>>“事件侦听器”
  • 这能回答你的问题吗? how to unbind all event using jquery

标签: jquery angularjs event-listener jquery-events


【解决方案1】:

您似乎需要专门选择元素才能从中删除事件处理程序。您可以使用.unbind() 从对象中删除所有事件,但我不相信您可以对整个页面执行此操作。 See this question.

【讨论】:

  • 事件是根据截图注册在文档上的吗? i.stack.imgur.com/Rea95.png
  • 无论如何我也尝试过这样做,但它似乎不起作用? $("html").off() 或 $("body").off()
  • 是的,我明白了。好吧,比我知识渊博的人将不得不接受这个。 :D
  • 刚刚做了 - 没有运气:/
  • 您是否在加载页面时将事件处理程序添加到文档中?我的意思是,你在做这样的事情吗,$(document).on('click', function(){})
猜你喜欢
  • 2018-08-08
  • 2014-04-19
  • 2012-12-18
  • 1970-01-01
  • 2021-09-05
  • 2020-11-13
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多