哪些jQuery事件不会冒泡? [英] Which jQuery events do not bubble?
问题描述
很简单,我一直在高低搜寻所有不会冒泡的jQuery事件的完整列表,但是我一直找不到.
Pretty straightforward, I've been searching high and low for a comprehensive list of all jQuery events that do not bubble but I have been unable to find one.
例如,我正在寻找image.load
,XMLHttpRequest.error
等事件.
For example I am looking for events like image.load
, XMLHttpRequest.error
, etc.
推荐答案
jQuery的文档on()
方法是这样的(在附加说明"下);
The docs for jQuery's on()
method says this (under "Additional Notes");
W3C将
focus
和blur
事件指定为不冒泡,但是jQuery定义了确实会冒泡的跨浏览器focusin
和focusout
事件.当focus
和blur
用于附加委托的事件处理程序时,jQuery映射名称并将其分别作为focusin
和focusout
传递.为了保持一致和清晰,请使用冒泡事件类型名称.
The
focus
andblur
events are specified by the W3C to not bubble, but jQuery defines cross-browserfocusin
andfocusout
events that do bubble. Whenfocus
andblur
are used to attach delegated event handlers, jQuery maps the names and delivers them asfocusin
andfocusout
respectively. For consistency and clarity, use the bubbling event type names.
在所有浏览器中,load
,scroll
和error
事件(例如,在<img>
元素上)不会冒泡.在Internet Explorer 8及更低版本中,paste
和reset
事件不会冒泡.不支持将此类事件与委托一起使用,但是当事件处理程序直接附加到生成元素时可以使用这些事件.事件.
In all browsers, the load
, scroll
, and error
events (e.g., on an <img>
element) do not bubble. In Internet Explorer 8 and lower, the paste
and reset
events do not bubble. Such events are not supported for use with delegation, but they can be used when the event handler is directly attached to the element generating the event.
我已经加上最相关的句子以供强调.
I've bolded the most relevant sentences for emphasis.
文档中的较早版本(在直接和委托的事件"下,它也这样说:
Earlier in the docs (under "direct and delegated events", it also says this:
在Internet Explorer 8及更低版本中,诸如
change
和submit
之类的一些事件本身并不是冒泡的,但是jQuery修补了这些事件以冒泡并创建一致的跨浏览器行为.
In Internet Explorer 8 and lower, a few events such as
change
andsubmit
do not natively bubble but jQuery patches these to bubble and create consistent cross-browser behavior.
您还将发现 mouseleave
和
You'll also find that mouseleave
and mouseenter
do not bubble (use the mouseover
and mouseout
events for that). This is discussed in their respective docs.
我不会开始全面地提及上述列表,但这只是一个开始.我不确定XMLHttpRequest如何进入您的问题;它不是DOM的一部分,因此没有任何祖先,因此不能像普通DOM事件一样真正地冒泡.
I wouldn't begin to call the above list comprehensive, but it's a start. I'm not sure how XMLHttpRequest comes into it in your question; it isn't part of the DOM, therefore doesn't have any ancestors, therefore cannot really bubble in the same way as normal DOM events.
这篇关于哪些jQuery事件不会冒泡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!