# # # Two ways to bind
(DOM0) 1.obj.onclick = fn;
(DOM2) 2.
Ie:obj.attachEvent (event name, event function);
1. No capture (non-standard IE standard IE has IE6 to 10 below)
2. Event name has on
3. Sequence of event function execution: Standard ie-"positive sequence non-standard ie-" reverse order
4.this pointing to Window
Standard: Obj.addeventlistener (event name, event function, whether capture);
1. There is a capture
2. Event name not on
3. The order in which events are executed is a positive sequence
4.this the object that triggered the event
Document.attachevent (' onclick ', fn2);
Document.attachevent (' onclick ', function () {
Fn1.call (document);
});
Capture: Default is false: Bubble true: Capture
Document.addeventlistener (' Click ', Fn1, false);
Document.addeventlistener (' Click ', Fn2, false);
Attention
IE stands for: non-standard IE and standard IE
The standard stands for: standard IE and chrome Firefox ....
# # Synchronous This
function bind (obj, Evname, fn) {
if (Obj.addeventlistener) {//In addition to IE low version can enter
Obj.addeventlistener (Evname, FN, false);
} else {
Obj.attachevent (' on ' + evname, function () {
Fn.call (obj);
});
}
}
Bind (document, ' click ', fn1);
# # # Two different ways to bind
Means of canceling bubbling: Event.cancelbubble = true; (deprecated)
Event.stoppropagation ();
The first type: Default bubbling,
The first: Only one homogeneous event can be bound on an element, and if you continue to bind, the second event function overrides the first
The second type:
Attachevent
Default bubbling
AddEventListener
Whether to capture: false by default
Third parameter: false: Bubbling
true: Capture
The second type: one element can be bound to a number of similar events, they will be executed
# # # Event Unbind
DOM0: To dismiss an event is fairly straightforward, just need to register the event again and set the value to NULL
The principle is that the last registered event is to overwrite the previous one, and the last registration event is set to NULL,
The event binding is also dismissed.
Dom2:removeeventlistener
De-event syntax: Btn.removeeventlistener ("event name", "Event callback", "Capture/bubble");
DetachEvent (IE)
Summary of # #
OnClick form: bubbling
Attachevent: Bubbling
AddEventListener: Third parameter (false: bubbling; true: Capture)
Mobile and PC-side event binding and canceling browser default style and de-bubbling