// Method for adding a function
Function addEvent (node, type, listener ){
If (node. addEventListener ){
// W3C method (DOM method)
// The false statement in the following statement is used for the bubble stage. If it is true, it is used for the capture stage (IE does not support capturing). Therefore, false is used for unification.
Node. addEventListener (type, listener, false );
Return true;
} Else if (node. attachEvent ){
// MSIE method (IE method)
Node ['E' + type + listener] = listener;
Node [type + listener] = function (){
Node ['E' + type + listener] (window. event );
};
Node. attachEvent ('on' + type, node [type + listener]);
Return true;
}
// If neither method is available, false is returned.
Return false;
}
// Method for removing a function
Function removeEvent (node, type, listener ){
If (node. addEventListener ){
Node. removeEventListener (type, listener, false );
Return true;
} Else if (node. detachEvent ){
Node. detachEvent ('on' + type, listener );
Return true;
}
// If neither method is available, false is returned.
Return false;
}
// The method for adding a load event is as follows:
1. function addLoadEvent (func ){
Var oldonload = window. onload;
If (typeof window. onload! = "Function "){
Window. onload = func;
} Else {
Window. onload = function (){
Oldonload ();
Func ();
}
}
}
2. // use the above addEvent Method
AddEvent (window, 'load', fn );