你如何记录由 jQuery 中的元素触发的所有事件? [英] How do you log all events fired by an element in jQuery?
本文介绍了你如何记录由 jQuery 中的元素触发的所有事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望看到在用户与其交互时由输入字段触发的所有事件.这包括以下内容:
<块引用>- 点击它.
- 点击关闭它.
- 进入它.
- 远离它.
- Ctrl+C 和 Ctrl+V 在键盘上.
- 右键单击 -> 粘贴.
- 右键单击 -> 剪切.
- 右键单击 -> 复制.
- 从另一个应用程序拖放文本.
- 使用 Javascript 修改它.
- 使用调试工具(如 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:
- Clicking on it.
- Clicking off it.
- Tabbing into it.
- Tabbing away from it.
- Ctrl+C and Ctrl+V on the keyboard.
- Right click -> Paste.
- Right click -> Cut.
- Right click -> Copy.
- Dragging and dropping text from another application.
- Modifying it with Javascript.
- 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屋!
查看全文