JQuery 事件是否可用于 Dom addEventListener? [英] Are JQuery events usables with Dom addEventListener?

查看:27
本文介绍了JQuery 事件是否可用于 Dom addEventListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 Bootstrap4 alpha,出于某些调查目的,我正在尝试使用 DOM addEventListener() 捕获 JQuery 事件.

I'm using Bootstrap4 alpha in my project, and for some investigations purposes, I'm trying to catch a JQuery event using DOM addEventListener().

使用 JQuery $("#mypanel").trigger("shown.bs.collapse") 函数在它的 折叠 组件.

The event is fired using the JQuery $("#mypanel").trigger("shown.bs.collapse") function by bootstrap in it's collapse component.

如果我尝试使用 JQuery $("#mypanel").on("shown.bs.collapse", ... ) 函数来捕捉它,一切正常.但是如果我在相应的 DOM 元素上使用 $("#mypanel").get(0).addEventListener("shown.bs.collapse", ... ) ,则事件不是抓到"

If i try to catch it using the JQuery $("#mypanel").on("shown.bs.collapse", ... ) function, everything works just fine. But if i use $("#mypanel").get(0).addEventListener("shown.bs.collapse", ... ) on the corresponding DOM elements, the event is not "catched"

JQuery事件系统和标准DOM事件系统不兼容吗?

Are JQuery event system and standard DOM event system are NOT compatibles?

让我认为它们实际上不兼容的一件事是,如果我使用 Chrome 的 monitorEvents() 函数来跟踪shown.bs.collapse".事件,它根本不会出现.

One thing that make me think they are actually incompatible, is that if I use the Chrome monitorEvents() function to track the "shown.bs.collapse" event, it simply do not appear.

欢迎对此提出任何反馈.

Any feedback about that is welcome.

克莱门特

推荐答案

不,您不能将 jQuery 自定义事件与常规 JavaScript 事件引擎一起使用.

No, you can't use jQuery custom events with the regular JavaScript event engine.

将 jQuery 事件系统视为标准 DOM 事件系统的扩展.jQuery 可以知道浏览器引发的所有事件,因为它可以为它创建实际的事件处理程序.它也可以有自己的自定义事件,因为当您调用 .trigger('your.custom.event') 时,jQuery 可以在引发实际的浏览器事件.

Think of the jQuery event system as an extension of the standard DOM event system. jQuery can know about all of the events that the browser raises, because it can create actual event handlers for it. It can also have its own custom events because when you call .trigger('your.custom.event') jQuery can first check for its own stored event handlers for that (custom) event, before raising an actual browser event.

这篇关于JQuery 事件是否可用于 Dom addEventListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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