There is no such object in FireFox. If function nested calls exist, the Event must be continuously passed down, for example, in the following scenario.
Copy codeThe Code is as follows:
<Div style = "background-color: Red; width: 300px; height: 300px;" onclick = "Test (event, this ); "id =" panel "> </div>
Function Test (event, dom ){
Test1 (event );
}
Function Test1 (event ){
Test2 (event );
}
Function Test2 (event ){
Alert(event.tar get. id );
}
To use event in the Test2 method, you must write it as follows. In a certain scenario, for example, to add a new function, you need to modify the original Test2 method and access the event object. The signature of the original Test2 method is Test2 () and there is no parameter event, in this case, we need to modify Test2 () to Test2 (event), which is very unattractive. Although JavaScript-like modification is a method overload, it also destroys the original method signature.
Is there a global variable like window. event in FireFox to get the event?
Unfortunately, FireFox does not have an object model, but it can be obtained using a work und. For example:
Copy codeThe Code is as follows:
Function GetEvent (caller ){
If (document. all)
Return window. event; // For IE.
If (caller = null | typeof (caller )! = "Function ")
Return null;
While (caller. caller! = Null ){
Caller = caller. caller;
}
Return caller. arguments [0];
}
Here, document. all is not good for determining whether it is an IE browser. We should use UserAgent to determine whether it is a good implementation in JQuery and other class libraries.
In this way, the Test2 method does not need to modify the method signature:
Copy codeThe Code is as follows:
Function Test2 (){
Var event = GetEvent (Test2 );
Alert (GetEventTarget (event). id );
}
Function GetEventTarget (event ){
If (document. all)
Return event. srcElement;
Return event.tar get;
}
Why can I write the GetEvent method and get the Event?
In the event model of Firefox, the initial event call passes the event display to the method. Therefore, you can write the GetEvent method to obtain the event that invokes JavaScript.
Screen. width-300) this. width = screen. width-300 "border = 0>