This article will introduce in detail the implementation process of js removal event js binding events. For more information, see
The Code is as follows:
/**
* @ Description event binding, compatible with various browsers
* @ Param target event trigger object
* @ Param type event
* @ Param func event handler
*/
Function addEvents (target, type, func ){
If (target. addEventListener) // non-ie and ie9
Target. addEventListener (type, func, false );
Else if (target. attachEvent) // ie6 to ie8
Target. attachEvent ("on" + type, func );
Else target ["on" + type] = func; // ie5
};
The Code is as follows:
/**
* @ Description event removal, compatible with various browsers
* @ Param target event trigger object
* @ Param type event
* @ Param func event handler
*/
Function removeEvents (target, type, func ){
If (target. removeEventListener)
Target. removeEventListener (type, func, false );
Else if (target. detachEvent)
Target. detachEvent ("on" + type, func );
Else target ["on" + type] = null;
};