如何创建侦听每种类型事件的侦听器 [英] How do I create a listener that listens for every type of event

查看:101
本文介绍了如何创建侦听每种类型事件的侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这纯粹是出于调试目的。是否有一个命令,如

This is purely for debugging purposes. Is there a single command like

addEventListener('*', myHandler) 

本地js中的

in native js or

$(document).on('*', myHandler)

在jQuery中可以监听任何事件,无论什么类型或命令空间并在事件发生时调用myHandler?

in jQuery that would listen for any event no matter what type or namespace and call myHandler when an event happens?

或者浏览器自带的devtools中是否有东西可以让你看到所有事件?

Or is there something in the browser's own devtools that might let you see all the events?

推荐答案

Chrome的开发工具可以做到这一点。打开它们,转到 Sources 标签,然后在右侧列中查看可展开/可折叠的子窗格。展开名为事件侦听器断点的那个。这里有可扩展的复选框选项,允许您勾选您想要侦听的任何事件。一旦你检查了它们中的任何一个,一旦发生这种类型的事件,Chrome就会破解JS代码。

Chrome's dev tools can do this. Open them up, go to the Sources tab, and look in the right-hand column with the expandable/collapsible sub-panes. Expand the one called Event Listener Breakpoints. Under here are expandable checkbox selections that allow you to tick any events that you wish to listen for. Once you check any of them, Chrome will break in JS code as soon as an event of that type occurs.

假设你的 myHandler function包含您只想执行调试的代码,您可以在控制台中运行此代码,或通过控制台调用该函数。

Assuming your myHandler function contains code you just want to execute for debugging, you can just run this code in the console, or call the function via console.

这篇关于如何创建侦听每种类型事件的侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆