JavaScript中的事件处理程序是否按顺序调用? [英] Are event handlers in JavaScript called in order?
问题描述
这个已更改虽然 DOM 2级事件规范确实状态为/ p>
当事件达到目标时,任何事件监听器都注册在
EventTarget
被触发。虽然所有EventListeners
EventTarget
中的
保证由任何
由EventTarget
,无规范被设为
订单,他们将收到与其他
EventListeners
在EventTarget
。
目前的 DOM 3级事件规范现在表示
实现必须确定当前目标的候选人
事件侦听器。
这必须是当前目标以注册顺序注册
的所有事件监听器的列表。HTML5
定义侦听器的顺序通过事件处理程序
属性注册。
[...]
最后,实现必须处理所有候选人事件
处理程序
按顺序 [...]
但是,在 DOM 4草案。
If I attach multiple event handlers to a single event on a single DOM element, are the event handlers guaranteed to be called in the order they were added? Or should I not rely on this behavior?
This has been changed with DOM3! While the DOM level 2 events specification did state
When the event reaches the target, any event listeners registered on the
EventTarget
are triggered. Although allEventListeners
on theEventTarget
are guaranteed to be triggered by any event which is received by thatEventTarget
, no specification is made as to the order in which they will receive the event with regards to the otherEventListeners
on theEventTarget
.
The current DOM level 3 events specification does now state
The implementation MUST determine the current target's candidate event listeners. This MUST be the list of all event listeners that have been registered on the current target in their order of registration.
HTML5
defines the ordering of listeners registered through event handler attributes. […]Finally, the implementation MUST process all candidate event handlers in order […]
However, I can't find a reference to this behaviour in the DOM 4 draft any more.
这篇关于JavaScript中的事件处理程序是否按顺序调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!