JQuery事件是否可以与Dom addEventListener一起使用? [英] Are JQuery events usables with Dom addEventListener?

查看:115
本文介绍了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)触发事件。触发器(shown.bs.collapse)通过bootstrap的折叠组件来实现。

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 actualy 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 !!

非常感谢!

Clément

推荐答案

不,你不能在常规JavaScript中使用jQuery自定义事件事件引擎。

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天全站免登陆