javascript – HTML事件处理程序与DOM级别0事件处理程序之间的区别

有人可以告诉我在JavaScript中实现HTML事件处理程序与DOM Level 0事件处理程序有什么区别?
最佳答案
DOM0事件是HTML和XHTML规范中定义为内在事件的声明性事件:

Intrinsic events are attributes that are used in conjunction with elements that can have specific events occur when certain actions are performed by the user. The attributes indicated in the following table are added to the attribute set for their respective elements only when the modules defining those elements are selected.

Certain elements of a markup language may have associated event handlers that are activated when certain events occur. User agents need to be able to identify those elements with event handlers statically associated (i.e., associated in the content, not in a script). In HTML 4 ([HTML4], section 18.2.3), intrinsic events are specified by the attributes beginning with the prefix “on”: onblur, onchange, onclick, ondblclick, onkeydown, onkeypress, onkeyup, onload, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onreset, onselect, onsubmit, and onunload.

Internet Explorer has the correct scope for event handlers defined using the DOM Level 0 method of property assignment but not when using attachEvent().

 The Level 0 DOM supports the following nodeLists:

document.images[], which grants access to all images on the page.
document.forms[], which grants access to all forms on the page.
document.forms[].elements[], which grants access to all form fields in one form, whatever their tag name. This nodeList is unique to the Level 0 DOM; the W3C DOM does not have a similar construct.
document.links[], which grants access to all links () on the page.
document.anchors[], which grants access to all anchors () on the page.

The focus events defined in this specification occur in a set order relative to one another. The following is the typical sequence of events when a focus is shifted between elements (this order assumes that no element is initially focused):


Event Name  Notes
1.  focusin Sent before first target element receives focus
2.  focus   Sent after first target element receives focus
3.  focusout    Sent before first target element loses focus
4.  focusin Sent before second target element receives focus
5.  blur    Sent after first target element loses focus
6.  focus   Sent after second target element receives focus

The following is the typical sequence of events when a focus is shifted between elements, including the deprecated DOMFocusIn and DOMFocusOut events. The order shown assumes that no element is initially focused.

C.2.1 Legacy FocusEvent event order

Event Name  Notes
1.  focusin Sent before first target element receives focus
2.  focus   Sent after first target element receives focus
3.  DOMFocusIn  If supported
4.  focusout    Sent before first target element loses focus
5.  focusin Sent before second target element receives focus
6.  blur    Sent after first target element loses focus
7.  DOMFocusOut If supported
8.  focus   Sent after second target element receives focus
9.  DOMFocusIn  If supported

HTML事件是DOM规范中定义为HTMLEvents的命令事件:

<iframe src="https://www.w3.org/DOM/Graphics/dom2-map.svg" width="900" height="400"></iframe>
<img src="https://www.w3.org/TR/DOM-Level-3-Events/images/eventflow.svg" width="400" height="400"/>

参考

> XHTML Modularization: Intrinsic Events Module
> HTML Living Specification: Events – IDL Definitions
> DOM3 Events Semantic Requirements
> Techniques for User Agent Accessibility Guidelines 1.0, Section 3.11: Script and applet techniques – Script Techniques
> UI Events Specification
> Can Text Nodes Receive Events?
> How to use the Level 0 DOM
> GitHub – Benvie/idl-for-javascript: IDL converted to a format and semantics usable by JavaScript
> GitHub – jsantell/chrome-api-definitions: Definition generator for Chrome Platform APIs
> Open Mobile Alliance – Supporting Data
> DOM handleEvent: a cross-platform standard since year 2000
> IDL interface rules – Mozilla | MDN

转载注明原文:javascript – HTML事件处理程序与DOM级别0事件处理程序之间的区别 - 代码日志