Home >Web Front-end >JS Tutorial >js remove event js binding event instance application_javascript skills

js remove event js binding event instance application_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:47:501261browse
Copy code The code is as follows:

/**
* @description event binding, compatible with all browsers
* @param target event trigger object
* @param type event
* @param func event processing function
*/
function addEvents(target , type, func) {
if (target.addEventListener) //Not 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
};

Copy code The code is as follows:

/**
* @description event removal, compatible with all browsers
* @param target event trigger object
* @param type event
* @param func event handler function
*/
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;
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn