I encountered this small problem before, but I did not summarize it.
Now again, to get an accurate conclusion, record it:
Example: whether all Event objects among multiple execution functions of the same Event are complete.
For example:Copy codeThe Code is as follows: dom. addEvent ('click', fna );
Dom. addEvent ('click', fnb );
1: The attribute added to the Event object in fna is accessible to the Event object in the fnb function that is executed afterwards?
2: When the fna/fnb function is executed, is the Event object fully equal to Eventfna === Eventfnb?
The standard document is too long. What is the rule here? Lazy...
For Jquery, the Event objects among multiple execution functions are all equal for the same Event.
In the implementation of Jquery live binding events, liveHandler, a function that may be executed repeatedly, relies on the liveFired attribute of the Event object to exit the function at the beginning of the liveHandler executed after the first time:Copy codeThe Code is as follows: if (event. liveFired = this | ...){
Return;
}
///....
Event. liveFired = this;
Test:Copy codeThe Code is as follows: function a (e ){
E. abc = function (){
Alert ();
};
PrevEvent = e;
PrevIeEvent = window. event;
}
Function B (e, event ){
E. abc (); // fn
Alert (e === prevEvent); // true
If (event = window. event ){
Alert (event = e); // false
Alert (event === prevIeEvent); // false
Alert (event === prevEvent); // false
}
}
Var t = document. getElementById ("p ");
If (t. addEventListener ){
T. addEventListener ('click', a, false );
T. addEventListener ('click', B, false)
} Else {
T. attachEvent ('onclick', B );
T. attachEvent ('onclick',)
}
For native Event binding methods [addEventListener, attachEvent], event objects between multiple execution functions (events passed through parameters) are all equal. in IE, window is used. event objects obtained in the Event form are incomplete. And events passed through parameters.
For bubble events:Copy codeThe Code is as follows: dom. addEvent ('click', fna );
DomParentNode. addEvent ('click', fnb );
In jquery, when an Event is triggered in trigger form, the Event objects in functions between bubble events are all equal. The event triggered by actual user behavior is not the same object. Custom Attributes cannot be passed. The value setting does not affect the true originalEvent.
[AddEventListener, attachEvent] using native binding Event Mode:Copy codeThe Code is as follows: function a (e ){
E. abc = function (){
Alert ();
};
PrevEvent = e;
PrevIeEvent = window. event;
}
Function B (e, event ){
Alert (e. abc); // fn
Alert (e === prevEvent); // true
If (event = window. event ){
Alert (event = e); // false
Alert (event === prevIeEvent); // false
Alert (event === prevEvent); // false
}
}
Var t = document. getElementById ("p ");
If (t. addEventListener ){
T. addEventListener ('click', a, false );
Document. body. addEventListener ('click', B, false );
} Else {
T. attachEvent ('onclick', );
Document. body. attachEvent ('onclick', B );
}
The result is that when attachEvent is bound to an Event, the Event objects in the function of the bubble Event in IE are inconsistent. FF and so on.
In fact, the Event objects between non-IE, Event object Propagation, or multiple functions triggered by the same dom node are all. It has nothing to do with the binding form [addEventListener/DOM0.
In IE, only the Event objects (attachEvent) passed by parameters between multiple functions triggered by dom nodes are all.