有人可以告诉我在JavaScript中实现HTML事件处理程序与DOM Level 0事件处理程序有什么区别吗?
答案 0 :(得分:0)
DOM0事件是在HTML和XHTML规范中定义为内在事件的声明性事件:
内部事件是与在用户执行某些操作时可能发生特定事件的元素结合使用的属性。仅当选择定义这些元素的模块时,下表中指示的属性才会添加到其各自元素的属性集中。
标记语言的某些元素可能具有在发生特定事件时激活的关联事件处理程序。用户代理需要能够使用静态关联的事件处理程序来识别那些元素(即,在内容中关联,而不是在脚本中)。在HTML 4([HTML4],第18.2.3节)中,内部事件由以":
onblur, onchange, onclick, ondblclick, onkeydown, onkeypress, onkeyup, onload, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onreset, onselect, onsubmit, and onunload
开头的前缀"开头的属性指定。Internet Explorer具有使用DOM Level 0属性赋值方法定义的事件处理程序的正确范围,但在使用
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.
本规范中定义的焦点事件以相对于彼此的设定顺序发生。以下是焦点在元素之间移动时的典型事件序列(此顺序假定最初没有元素聚焦):
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
以下是焦点在元素之间切换时的典型事件序列,包括不推荐使用的DOMFocusIn和DOMFocusOut事件。显示的顺序假定最初没有元素聚焦。
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"/>
&#13;
<强>参考强>