However, there is no such object in FireFox. If there are nested functions, the Event needs to be passed down continuously, such as the following scenario.
<div style="background-color:Red; width:300px; height:300px;" onclick="Test(event,this);" ></div>
function Test(event,dom){
Test1(event);
}
function Test1(event){
Test2(event);
}
function Test2(event){
alert();
}
In the Test2 method, you need to use event, so you need to write it like this. If in a certain scenario, such as adding a new function, you need to modify the original Test2 method and access the event object. The original Test2 method's signature is Test2() and there is no parameter event. At this time, you need to modify Test2() to Test2(event) is very unsightly. Although JavaScript's modification is an overload of the method, it also destroys the original method signature.
Is there such a global variable in FireFox to get event?
Unfortunately, FireFox's object model is not available, but can be obtained using workarounds. For example:
function GetEvent(caller){
if()
return ; //For IE.
if(caller == null || typeof(caller) != "function")
return null;
while( != null){
caller = ;
}
return [0];
}
It is not good to use this to determine whether it is an IE browser. UserAgent should be used to judge that there are good implementations in class libraries such as JQuery.
In this way, the Test2 method above can be used to change the method signature:
function Test2(){
var event = GetEvent(Test2);
alert(GetEventTarget(event).id);
}
function GetEventTarget(event){
if()
return ;
return ;
}
Why can I write the GetEvent method and get Event?
Because the initial event call in Firefox's event model passes the event display to the method, you can write the GetEvent method to get the event that evokes JavaScript.
Copy the codeThe code is as follows:
<div style="background-color:Red; width:300px; height:300px;" onclick="Test(event,this);" ></div>
function Test(event,dom){
Test1(event);
}
function Test1(event){
Test2(event);
}
function Test2(event){
alert();
}
In the Test2 method, you need to use event, so you need to write it like this. If in a certain scenario, such as adding a new function, you need to modify the original Test2 method and access the event object. The original Test2 method's signature is Test2() and there is no parameter event. At this time, you need to modify Test2() to Test2(event) is very unsightly. Although JavaScript's modification is an overload of the method, it also destroys the original method signature.
Is there such a global variable in FireFox to get event?
Unfortunately, FireFox's object model is not available, but can be obtained using workarounds. For example:
Copy the codeThe code is as follows:
function GetEvent(caller){
if()
return ; //For IE.
if(caller == null || typeof(caller) != "function")
return null;
while( != null){
caller = ;
}
return [0];
}
It is not good to use this to determine whether it is an IE browser. UserAgent should be used to judge that there are good implementations in class libraries such as JQuery.
In this way, the Test2 method above can be used to change the method signature:
Copy the codeThe code is as follows:
function Test2(){
var event = GetEvent(Test2);
alert(GetEventTarget(event).id);
}
function GetEventTarget(event){
if()
return ;
return ;
}
Why can I write the GetEvent method and get Event?
Because the initial event call in Firefox's event model passes the event display to the method, you can write the GetEvent method to get the event that evokes JavaScript.