问题
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.
For example I am looking for events like image.load
, XMLHttpRequest.error
, etc.
回答1:
The docs for jQuery's on() method says this (under "Additional Notes");
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.In all browsers, the
load
,scroll
, anderror
events (e.g., on an<img>
element) do not bubble. In Internet Explorer 8 and lower, thepaste
andreset
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:
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.
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.
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.
回答2:
According to DOM Level 3 Events spec,
Events that bubble:
beforeinput
,click
,compositionstart
,compositionupdate
,compositionend
,dblclick
,focusin
,focusout
,input
,keydown
,keyup
,mousedown
,mousemove
,mouseout
,mouseover
,mouseup
,select
,wheel
.Events that don't bubble:
abort
,blur
,error
,focus
,load
,mouseenter
,mouseleave
,resize
,scroll
(*),unload
Note DOM Level 3 Events doesn't define all events, some of them are defined by HTML5 spec.
That spec is less clear, because doesn't always say if events bubble and defines some events in non-normative sections. In one of these it says that drag-and-drop events bubble:
dragstart
, drag
, dragenter
, dragexit
, dragleave
, dragover
, drop
, dragend
.
(*) When dispatched on the Document
element, scroll
event type MUST bubble to the defaultView
object.
来源:https://stackoverflow.com/questions/25556817/which-jquery-events-do-not-bubble