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.