Copy codeThe Code is as follows:
Function addEventSimple (obj, evt, fn ){
If (obj. addEventListener)
Obj. addEventListener (evt, fn, false );
Else if (obj. attachEvent)
Obj. attachEvent ('on' + evt, fn );
}
Function removeEventSimple (obj, evt, fn ){
If (obj. removeEventListener)
Obj. removeEventListener (evt, fn, false );
Else if (obj. detachEvent)
Obj. detachEvent ('on' + evt, fn );
}
The usage is as follows:
Copy codeThe Code is as follows:
AddEventSimple (element, 'click', functionname );
AddEventSimple (document, 'load', functionname2 );
Now, if an element is clicked, functionaname is triggered. The same document also has the onload event handler functionname2.
Defect: the keyword "this" in IE is not an element you think points to the trigger event, but to the entire document.
Address: http://www.quirksmode.org/js/eventSimple.html
When I went back to my hometown for the New Year, I couldn't release it in time. The next year will continue and everyone will have a happy new year!
Reprinted please keep the following information
Author: Beiyu (tw: @ rehawk)
Source: beiyu.cnblogs.com