Javascript usage of attachevent and addeventlistener

Source: Internet
Author: User
Javascript usage of attachevent and addeventlistener

 

The attachevent method attaches other processing events to an event. (Mozilla series not supported) The addeventlistener method is used in the Mozilla series for example: Java code document. getelementbyid ("BTN "). onclick = Method1; document. getelementbyid ("BTN "). onclick = method2; document. getelementbyid ("BTN "). onclick = method3; document. getelementbyid ("BTN "). onclick = Method1; document. getelementbyid ("BTN "). onclick = method2; document. getelementbyid ("BTN "). onclick = method3; if it is written in this way, only medhot3 will be executed as follows: Java code: var btn1obj = Document. getelementbyid ("btn1"); // object. attachevent (event, function); btn1obj. attachevent ("onclick", Method1); btn1obj. attachevent ("onclick", method2); btn1obj. attachevent ("onclick", method3); var btn1obj = document. getelementbyid ("btn1"); // object. attachevent (event, function); btn1obj. attachevent ("onclick", Method1); btn1obj. attachevent ("onclick", method2); btn1obj. attachevent ("onclick", method3); the execution sequence is If method3-> method2-> Method1 is a Mozilla series and does not support this method, you need to use the addeventlistener Java code: var btn1obj = document. getelementbyid ("btn1"); // element. addeventlistener (type, listener, usecapture); btn1obj. addeventlistener ("click", Method1, false); btn1obj. addeventlistener ("click", method2, false); btn1obj. addeventlistener ("click", method3, false); var btn1obj = document. getelementbyid ("btn1"); // element. addeventlistener (Type, Listener, usecapture); btn1obj. addeventlistener ("click", Method1, false); btn1obj. addeventlistener ("click", method2, false); btn1obj. addeventlistener ("click", method3, false); the execution sequence is Method1-> method2-> method3 instance: 1. Java code: var El = editform_document.body; // get the object first. editform_document is actually an IFRAME if (El. addeventlistener )... {el. addeventlistener ('click', kinddisablemenu, false);} else if (El. attachevent )... {el. attachevent ('onclick', kinddisablemenu);} var El = editform_document.body; // get the object first. editform_document is actually an iframeif (El. addeventlistener )... {el. addeventlistener ('click', kinddisablemenu, false);} else if (El. Attachevent)... {El. attachevent ('onclick', kinddisablemenu);} 2. Java code: If (window. addeventlistener )... {window. addeventlistener ('load', _ Uco, false);} else if (window. attachevent )... {window. attachevent ('onload', _ Uco );}
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.