window.event problems
Problem Description: Window.event can only run under IE, but not under Firefox, because Firefox event can only be used on the spot where events occur.
Workaround: Add an event parameter to the function that occurred on the incident, and use var myevent = Evt?evt in the function body (assuming the parameter is EVT): (Window.event?window.event:null)
After the Firefox page is called, its Windows.event object is undefined:
- if (typeof (window.event) = = ' undefined ')
- Alert (' window.event is undefined. ');
- Else
- Alert (' window.event is defined. ');
The above code is executed in Firefox, with the result: "Window.event is undefined." Results in IE and chrome: "window.event is defined."
1. Passing the event parameter in a function
Pass the event parameter in the function so that we can be compatible with the acquisition of the event of IE and FF, as in the following function:
function _test (EVT)
{
Gets the source object that triggered the event
Print the object's Value property
}
So that's what we should do when we're using it:
<input type= ' button ' value= ' click me ' onclick= ' _test (event) '/>
2. Do not pass the event object in a function call
Although there is no parameter passed in the function, this has no effect on IE, because Window.event is a global object and can be called directly anywhere, but not at FF. So here we have to use another way to get it, as follows:
Unction _test2 ()
{
Arguments. callee. caller. //Get Event object
Gets the source object that triggered the event
Get button code
Print the object's Value property
if (window.navigator.userAgent.indexOf ("IE") >=1) {
Evt.keycode = 0;
Evt.returnvalue=false;
}else{
Evt.preventdefault ();
}
}
Then, we can use the same time as normal function call, directly enter the function name, as follows:
<input type= ' button ' value= ' click me2 ' onclick= ' _test2 () '/>
Event.srcelement problems
Problem description: Under IE, even object has Srcelement property, but no target property; Under Firefox, even object has the target property, but there is no srcelement attribute.
Workaround: Use Srcobj = event.srcelement? Event.srcElement:event.target;
Compatibility of event events (GO)