Javascript incident handles an order (DOM incident handles an order)

Javascript incident handles an order (DOM incident handles an order)Javascript incident handles an order (DOM incident handles an order)

Appoint incident to handle the traditional pattern of the program through JavaScript, assign a function to handle program property to an incident namely. This kind of method that handles program assignment for incident appears in browser of the 4th acting Web, and still be supported for all and contemporary browser up to now. The reason is simple, 2 it is to have the advantage that crosses a browser. Want to use JavaScript to appoint incident to handle an order, must obtain the adduction of a boy or girl friend that wants an operation above all.

DOM incident handles an order one

Every element (the episode that includes Window and Document) to have his handles program property, these attribute normally whole small letter, for example Onclick. the value of this kind of attribute the setting is a function, can appoint incident to handle an order, following place show:

Var Btn = Document.getElementById("myBtn");

Btn.onclick = Function(){

Alert("Clicked");

};

Here, we obtained the adduction of a pushbutton through documentation object, appointed Onclick incident to handle an order for it next. But want to notice, move to won't appoint incident to handle an order before in these code, so if these code are located in in the page at the back of pushbutton, how to click likely inside period of time do not have reaction.

The incident that this kind of method appoints handles a program to be considered as elemental method. Accordingly, at that time incident processing program is; moves in elemental scope in other words, the This in the program cites current element.

Var Btn = Document.getElementById("myBtn");

Btn.onclick = Function(){

Alert(this.id); //"myBtn "

};

Clicking what pushbutton shows is elemental ID, this ID is obtained through This.id. It is ID not just, can pass This to visit any attribute of the element and method in incident processing program actually. The effervescent stage that the incident that adds with this kind of means treats a program to be able to flow in incident is handled.

Want to delete designation incident to handle an order, should resemble only below the value setting that treats incident program property so is Null can:

Btn.onclick = Null; // deletes incident to handle an order

After incident processing program setting is Null, click pushbutton to will not any movements happen again.

DOM class incident handles an order 2 (incident is monitored)

The operation that is used at processing is appointed and deleting incident to handle an order: ADdEventListener() and RemoveEventListener() .

All DOM include these two methods in node, and they accept 3 parameter: ?  of  of collection of  of Chi of ⒆ of  of  of collection of   vasting neon crowded  of class of haze of Sun of Jia of Li of W of idle of  of post haze class blocks ostrich of  of  of dusk of silk ribbon horsefly?true of  of Quan asking  , express to be in capture level calls incident to if be False,handle program; , express to call incident to handle an order in effervescent phase.

Incident is added to handle an order for Click incident on pushbutton.

Var Btn = Document.getElementById("myBtn");

Btn.addEventListener("click

未经允许不得转载:News » Javascript incident handles an order (DOM incident handles an order)