Attachevent usage in JavaScript

Source: Internet
Author: User

This article mainly introduces the use of attachevent in JavaScript, examples of JavaScript in the context of event binding skills, the need for friends can refer to the

This example describes the Attachevent usage in JavaScript. Share to everyone for your reference. The specific analysis is as follows:

Generally we add events in JS, this is the case

Obj.onclick=method

This way of binding events, compatible with mainstream browsers, but what if one element adds multiple times to the same event?

?

1 2 3 Obj.onclick=method1 obj.onclick=method2 obj.onclick=method3

If this is the case, then only the last bound event, here is method3 will be executed, this time we can not use the way of OnClick, the protagonist changed debut, in IE we can use the Attachevent method

?

1 2 3 Btn1obj.attachevent ("onclick", method1); Btn1obj.attachevent ("onclick", method2); Btn1obj.attachevent ("onclick", method3);

Using the format is preceded by the event type, note that you need to add on, such as Onclick,onsubmit,onchange, the order of execution is

Method3->method2->method1

Unfortunately, this Microsoft private approach, Firefox and other browsers do not support, fortunately they all support the AddEventListener method of the standard

?

1 2 3 Btn1obj.addeventlistener ("click", Method1,false); Btn1obj.addeventlistener ("click", Method2,false); Btn1obj.addeventlistener ("click", Method3,false);

The order of execution is method1->method2->method3

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The

The

wants this article to help you with your JavaScript programming.

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.