W3C DOM4 第10次工作草案(W3C Last Call Working Draft 10 July 2014)
来源:互联网 发布:淘宝联盟佣金结算 编辑:程序博客网 时间:2024/05/21 17:18
http://www.w3.org/TR/2014/WD-dom-20140710/
Table of Contents
- Goals
- 1 Conformance
- 1.1 Dependencies
- 1.2 Extensibility
- 2 Terminology
- 2.1 Trees
- 2.2 Strings
- 2.3 Ordered sets
- 2.4 Namespaces
- 3 Errors
- 3.1 Exception
DOMException
- 3.2 Interface
DOMError
- 3.3 Error names
- 3.1 Exception
- 4 Events
- 4.1 Introduction to "DOM Events"
- 4.2 Interface
Event
- 4.3 Interface
CustomEvent
- 4.4 Constructing events
- 4.5 Defining event interfaces
- 4.6 Interface
EventTarget
- 4.7 Dispatching events
- 4.8 Firing events
- 5 Nodes
- 5.1 Introduction to "The DOM"
- 5.2 Node tree
- 5.2.1 Mutation algorithms
- 5.2.2 Interface
NonElementParentNode
- 5.2.3 Interface
ParentNode
- 5.2.4 Interface
NonDocumentTypeChildNode
- 5.2.5 Interface
ChildNode
- 5.2.6 Old-style collections:
NodeList
andHTMLCollection
- 5.2.6.1 Interface
NodeList
- 5.2.6.2 Interface
HTMLCollection
- 5.2.6.1 Interface
- 5.3 Mutation observers
- 5.3.1 Interface
MutationObserver
- 5.3.2 Queuing a mutation record
- 5.3.3 Interface
MutationRecord
- 5.3.4 Garbage collection
- 5.3.1 Interface
- 5.4 Interface
Node
- 5.5 Interface
Document
- 5.5.1 Interface
DOMImplementation
- 5.5.1 Interface
- 5.6 Interface
DocumentFragment
- 5.7 Interface
DocumentType
- 5.8 Interface
Element
- 5.8.1 Interface
Attr
- 5.8.1 Interface
- 5.9 Interface
CharacterData
- 5.10 Interface
Text
- 5.11 Interface
ProcessingInstruction
- 5.12 Interface
Comment
- 6 Ranges
- 6.1 Introduction to "DOM Ranges"
- 6.2 Interface
Range
- 7 Traversal
- 7.1 Interface
NodeIterator
- 7.2 Interface
TreeWalker
- 7.3 Interface
NodeFilter
- 7.1 Interface
- 8 Sets
- 8.1 Interface
DOMTokenList
- 8.2 Interface
DOMSettableTokenList
- 8.1 Interface
- 9 Historical
- 9.1 DOM Events
- 9.2 DOM Core
- 9.3 DOM Ranges
- 9.4 DOM Traversal
- References
- Acknowledgments
Introduction to "DOM Events"
Throughout the web platform events are dispatched to objects to signal an occurrence, such as network activity or user interaction. These objects implement the EventTarget
interface and can therefore add event listeners to observe events:
obj.addEventListener("load", imgFetched)function imgFetched(ev) { // great success …}
Event listeners can be removed by utilizing the removeEventListener()
method, passing the same arguments.
Events are objects too and implement the Event
interface (or a derived interface). In the example above ev is the event. It is passed as argument to event listener's callback (typically a JavaScript Function as shown above). Event listeners key off the event's type
attribute value ("load
" in the above example). The event's target
attribute value returns the object to which theevent was dispatched (obj above).
Now while typically events are dispatched by the user agent as the result of user interaction or the completion of some task, applications can dispatch events themselves, commonly known as synthetic events:
// add an appropriate event listenerobj.addEventListener("cat", function(e) { process(e.detail) })// create and dispatch the eventvar event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}})obj.dispatchEvent(event)
Apart from signaling, events are sometimes also used to let an application control what happens next in an operation. For instance as part of form submission an event whose type
attribute value is "submit
" is dispatched. If this event's preventDefault()
method is invoked, form submission will be terminated. Applications who wish to make use of this functionality through eventsdispatched by the application (synthetic events) can make use of the return value of the dispatchEvent()
method:
if(obj.dispatchEvent(event)) { // event was not canceled, time for some magic …}
When an event is dispatched to an object that participates in a tree (e.g. an element), it can reach event listeners on that object's ancestors too. First all object's ancestor event listenerswhose capture variable is set to true are invoked, in tree order. Second, object's own event listeners are invoked. And finally, and only if event's bubbles attribute value is true, object'sancestor event listeners are invoked again, but now in reverse tree order.
Lets look at an example on how events work in a tree:
<!doctype html><html> <head> <title>Boring example</title> </head> <body> <p>Hello <span id=x>world</span>!</p> <script> function test(e) { debug(e.target, e.currentTarget, e.eventPhase) } document.addEventListener("hey", test, true) document.body.addEventListener("hey", test) var ev = new Event("hey", {bubbles:true}) document.getElementById("x").dispatchEvent(ev) </script> </body></html>
The debug
function will be invoked twice. Each time the events's target
attribute value will be the span
element. The first time currentTarget
attribute's value will be the document, the second time the body
element. eventPhase
attribute's value switches from CAPTURING_PHASE
to BUBBLING_PHASE
. If an event listener was registered for the span
element, eventPhase
attribute's value would have been AT_TARGET
.
- W3C DOM4 第10次工作草案(W3C Last Call Working Draft 10 July 2014)
- W3C 工作草案的完整WSDL 1.2 语法(摘自W3School)
- W3C首次发布SVG标记、SVG轮廓标准工作草案
- 温故知新:W3C发布10个XML规范草案 网络成全球数据库
- W3C工作流程 (W3C标准的各个级别)
- W3C
- w3c
- W3C
- W3C
- W3C
- webrtc1.0 w3c draft 2012.10.20
- W3C 接连推出 7 个 HTML 草案
- W3C工作流程
- W3C工作流程
- W3C工作流程
- W3C工作流程
- W3C工作流程
- W3C发布SVG的XML绑定语言(sXBL)草案
- 编译器以4字节对其
- Java内存管理机制
- 学习spring的一点点理解和总结
- Ducter能帮你!
- 基础总结篇之六:Intent应用详解
- W3C DOM4 第10次工作草案(W3C Last Call Working Draft 10 July 2014)
- js中ajax的用法
- nginx 权重分配
- android网络请求
- Inherits、CodeFile、CodeBehind的区别
- Dancing links 基础题
- 记录遇到的ios下的坑和bugs
- JqueryEasyUI datagrid通过struts请求从后台读取数据
- HTTP请求(GET与POST区别)和响应