//Method to add a function
function addEvent( node, type, listener) {
if( node.addEventListener ){
// W3C method (DOM method)
// false in the following statement It means that it is used in the bubbling phase. If it is true, it is used in the capturing phase (IE does not support capturing), so the reason for using false here is for the sake of unification.
node.addEventListener(type, listener, false);
return true; = function (){
node['e' type listener](window.event); true;
}
//If neither method is available, return false
return false;
}
//Method to remove 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); ; >}
//The method of adding a loading event is as follows
1.function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window .onload!="function"){
. 🎜> }
}
}
2.//Use the addEvent method above
addEvent(window, 'load', fn);