function addEventSimple(obj,evt,fn) {
if ( obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on' evt,fn);
}
removefunctionSimple(obj,evt,fn) {
if (obj.removeEventListener)
obj.removeEventListener(evt,fn,false);
else if (obj.detachEvent)
obj .detachEvent('on' evt,fn);
}
Usage is as follows:
addEventSimple(element,'click',functionname);
addEventSimple(document,'load',functionname2);
Now if the element element is clicked, functionaname will be triggered. The same document also has onload event handler functionname2.
Defect: The this keyword in IE does not point to the element that triggers the event as you imagine, but points to the entire document.
Original address: http://www.quirksmode.org/js/eventSimple.html
I went back to my hometown for the New Year, so I can’t publish it in time. I will continue next year. Happy New Year everyone!
Please keep the following information for reprinting
Author: Beiyu (tw:@rehawk)
Article source: beiyu.cnblogs.com
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