On Github leftstick / event-work
Created by Howard.Zuo / @leftstick
/ \ ---------------------| |--------------------- | element1 | | | | -----------------| |---------------- | | |element2 | | | | | | -------------| |------------ | | | | |element3 | | | | | | | ---------------------------- | | | ------------------------------------ | | Event BUBBLING | ---------------------------------------------
| | ---------------------| |-------------------- | element1 | | | | -----------------| |-------------- | | |element2 | | | | | | -------------| |---------- | | | | |element3 \ / | | | | | -------------------------- | | | ---------------------------------- | | Event CAPTURING | --------------------------------------------
| | / \ --------------------| |--| |-------------------- | element1 | | | | | | ----------------| |--| |-------------- | | |element2 | | | | | | | | ------------| |--| |--------- | | | | |element3 \ / | | | | | | | ----------------------------- | | | -------------------------------------- | | W3C event model | ------------------------------------------------
target.addEventListener(type, listener[, useCapture]);Param Type Detail type string A string representing the event type to listen for listener function The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a JavaScript function useCapture boolean If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture. See DOM Level 3 Events and JavaScript Event order for a detailed explanation. If not specified, useCapture defaults to false
target.attachEvent(event, handler);Param Type Detail event string A string representing any of the standard DHTML Events, case-insensitive. Must have 'on' as prefix, For example: onclick handler function The handler function