As we known, there are some functions about event operation:
attachEvent, dettachEvent // IE
addEventListener, removeEventListener //For Mozilla, Netscape, Firefox
Here, I provide some useful functions for easy your operate events.
In most time, I recommand your using fnSetEvent method.
function OGlobalScript_fnSetEvent(oElement, sEventName, sScript)
{
if (null == sScript || "" == sScript)
{
eval("oElement." + sEventName + " = null");
} else {
eval("oElement." + sEventName + " = function() {" + sScript + "}");
}
}
function OGlobalScript_fnAttachEvent(oElement, sEventName, fFunction)
{
if(window.addEventListener)
{ // Mozilla, Netscape, Firefox
oElement.addEventListener(sEventName, fFunction, false);
} else { // IE
oElement.attachEvent(sEventName, fFunction);
}
}
function OGlobalScript_fnDetachEvent(oElement, sEventName, fFunction)
{
if(window.removeEventListener)
{ // Mozilla, Netscape, Firefox
oElement.removeEventListener(sEventName, fFunction, false);
} else { // IE
oElement.detachEvent(sEventName, fFunction);
}
}