从页面中删除所有 Javascript 事件并将其放回原处
我想“暂停”页面的所有事件,这意味着删除所有事件集......并能够在之后将它们放回去。
即使第一部分=删除页面的所有事件,我也不知道该怎么做!你有想法吗?
我没有发现任何有用的东西!
编辑:
为什么?我想在已经加载的页面中执行操作。用户将与页面交互,我想控制交互...所以删除之前设置的所有交互。
I'd like to "pause" all the events of a page which means removes all the event set... and be able to put them back after.
Even the first part = removing all the events of a page, I don't see how to do so! Do you have ideas?
I don't find anything working for it!
Edit:
Why? I want to act in a page already loaded. The user will interact with the page and I want to control the interaction... so remove all the interactions previously set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用一个全局布尔变量
paused
来代替分离所有事件处理程序,该变量将在所有事件处理程序中进行检查。Instead of detaching all event handlers, you can have a global boolean variable
paused
which would be checked in all event handlers.我不知道你为什么要这样做...但是你可以将所有的 javascript 放入外部 .js 文件中(正如你应该已经做的那样。然后将一个 javascript 函数硬编码到你的页面中...它看起来像像这样:
我认为这会起作用......
}
I'm not sure why you would do this... but you could put all of your javascript into an external .js file (as you should already. Then have a single javascript function that's hardcoded into your page... it would look like this:
I think this would work...
}
这是我当前使用的解决方案:它并不能完全解决问题!
我在捕获阶段停止事件:我在文档对象上放置了一个侦听器来侦听捕获阶段的所有事件并停止传播。
+:
-:
您有更好的解决方案吗?
PS:如果找到更好的解决方案,我会继续更新这篇文章
Here is the currently solution I use: it doesn't solve the problem totally!
I stop the event during the capture phase: I put a listener on the document object to listen to all events in the capture phase and stop propagation.
+:
-:
Do you have a better solution?
P.S.: I'll continue to update this post if I find a better solution
对于任何 AJAX 交互,您当然至少可以使用 ajax 队列 中止任何连接,并且对于任何当前动画,您可以使用 stop();
for any AJAX interactions you can certainly at least abort any connections using ajax queue and for any current animations, you can use stop();
您可以使用
unbind()
删除所有事件You can use
unbind()
to remove all events您需要将所有事件侦听器存储在 eventMap 中。
添加事件
暂停事件
You'd need to store all the event listeners in a eventMap.
Add events with
Pause Events with