你如何记录由 jQuery 中的元素触发的所有事件? [英] How do you log all events fired by an element in jQuery?

查看:20
本文介绍了你如何记录由 jQuery 中的元素触发的所有事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望看到在用户与其交互时由输入字段触发的所有事件.这包括以下内容:

<块引用>

  1. 点击它.
  2. 点击关闭它.
  3. 进入它.
  4. 远离它.
  5. Ctrl+CCtrl+V 在键盘上.
  6. 右键单击 -> 粘贴.
  7. 右键单击 -> 剪切.
  8. 右键单击 -> 复制.
  9. 从另一个应用程序拖放文本.
  10. 使用 Javascript 修改它.
  11. 使用调试工具(如 Firebug)修改它.

我想使用 console.log 显示它.这在 Javascript/jQuery 中是否可行,如果可以,我该怎么做?

解决方案

$(element).on("click mousedown mouseup focus blur keydown change",function(e){控制台日志(e);});

这会给你很多(但不是全部)关于事件是否被触发的信息......除了像这样手动编码之外,我想不出任何其他方法来做到这一点.

I'd like to see all the events fired by an input field as a user interacts with it. This includes stuff like:

  1. Clicking on it.
  2. Clicking off it.
  3. Tabbing into it.
  4. Tabbing away from it.
  5. Ctrl+C and Ctrl+V on the keyboard.
  6. Right click -> Paste.
  7. Right click -> Cut.
  8. Right click -> Copy.
  9. Dragging and dropping text from another application.
  10. Modifying it with Javascript.
  11. Modifying it with a debug tool, like Firebug.

I'd like to display it using console.log. Is this possible in Javascript/jQuery, and if so, how do I do it?

解决方案

$(element).on("click mousedown mouseup focus blur keydown change",function(e){
     console.log(e);
});

That will get you a lot (but not all) of the information on if an event is fired... other than manually coding it like this, I can't think of any other way to do that.

这篇关于你如何记录由 jQuery 中的元素触发的所有事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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