//For non-delayed loading functions, conditional judgment will be performed every time it is called.
removefunctionHandler(target, eventType, handler) {
if(target.removeEventListener) {
target.removeEventListener(eventType,handler,false);
}else {
target.detachEvent( "on" eventType,handler);
}
}
//The delayed loading function will overwrite the original old function after the first call. The new function will be called again in the future and will not be called again. Make conditional judgments to improve efficiency
function addHandler(target, eventType, handler) {
if(target.addEventListener) {
addHandler = function(target, eventType, handler){
target.addEventListener (eventType,handler,false);
}
}else{
addHandler = function(target,eventType,handler){
target.attachEvent("on" eventType,handler);
}
}
addHandler(target, eventType, handler);
}
//Conditional preloading
//Conditional preloading ensures that all function calls take the same time. The cost is instrumentation when the script loads. Preloading is suitable for situations where a function will be used immediately and is used frequently throughout the page life cycle.
var addEventHandler = document.body.addEventListener ? function(target,eventType,handler) {
target.addEventListener(eventType,handler,false);
} : function(target,eventType,handler) ) {
target.attachEvent("on" eventType,handler);
}