JavaScript Event Learning Addendum addEventSimple

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.