2015-10-15 68 views
5

是否有人能告訴我在JavaScript中實現HTML事件處理程序與DOM級別0事件處理程序有什麼區別?HTML事件處理程序與DOM級別0事件處理程序之間的區別

+0

這可能對您有用:http://stackoverflow.com/q/5642659/830125 –

+0

非常感謝您,但它並沒有真正回答這個區別是什麼 – Jonny

+0

沒有DOM L0規範,該術語僅用於指非標準的廣泛功能。然後他們在HTML中被標準化。 – Oriol

回答

0

DOM0事件是在HTML和XHTML規格固有事件定義的聲明事件:

內在事件是配合使用元素的屬性,可以有當某些動作由執行特定事件發生用戶。只有在選擇了定義這些元素的模塊時,纔會將下表中指示的屬性添加到它們各自元素的屬性集中。

標記語言的某些元素可能具有關聯的事件處理程序,它們在發生某些事件時被激活。用戶代理需要能夠用靜態關聯的事件處理程序來標識這些元素(即,在內容中關聯,而不是在腳本中)。在HTML 4([HTML4],第18.2.3節)中,內部事件由以「on」開頭的屬性指定: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"/>

參考