js event binding

JavaScript has three kinds of events:

  • model
  • model

  • model
  • inline script

  • DOM2

1 model


, inline

 / / basic input type= abolished without < "button" value= "button" onclick= "alert ('Lee'); /> < input" type= "button" value= "button" onclick= "(box); /> 


 script model without var input = document.getElementsByTagName / [0] ('input'); / / input = function (object input.onclick) {/ / Alert ('Lee') to perform anonymous function; event handler effect}; when the onabort image when the image element the loading is interrupted when the onblur window, frame, all the form object when the focus is moved away from the object. When the onchange input box, select the box and text area when changing the value of one element and lose focus when onclick links, buttons, form object, image mapping area when the user clicks the object ondblclick links, buttons, form objects when the user double clicks the object ondragdrop window when the user takes an object to drop when the browser window onError script when the script syntax error occurs when the onfocus window, frame, all form objects when you click the mouse or mouse focus to the window or frame of onkeydown documents, images, links, forms when the button is pressed the onkeypress documents, images, links, forms when the button is pressed and then release the onkeyup documents, images, links, form when the button is released, onload theme framework set, image document or image after loading onun Load, the main frame set document or frame set after unloading the onmouseout link when you remove links OnMouseOver icon link when the mouse moves to link the onmove window when the browser window when the mobile onreset form form reset button click the reset button onresize window when choosing a form object onselect form elements when choosing a form object when the onsubmit form send the form to the server, 


"DOM2 model inline event" defines two methods for adding and deleting events, event handler operations: addEventListener and removeEventListener (< br>) (). These two methods include all DOM nodes, and they all accept 3 parameters; the event name, function, or bubble capture Boolean value (true capture, false said

 window.addEventListener ('load'bubble), function (ALERT) {('Lee')},; false; window.removeEventListener ('load', function) (('Mr.Lee')) {alert}, false); 

PS: IE to achieve the two similar method in DOM: attachEvent () and detachEvent (). These two methods accept the same parameters of
: event name and function. When

uses these two functions, it's the first thing to say differently:

 1. IE does not support capture, it only supports bubbles; 2. IE add events cannot shield duplicate functions; this in 3. IE points to window instead of DOM objects. 4. in traditional events, IE is unacceptable to event objects, but attchEvent () can be used, but there are some differences. ```javascript window.attachEvent ('load'), function ({alert ('Lee');}, false); window.detachEvent ('load', function) (alert ('Mr.Lee') {}; false, ```

) in

PS:IE (attachEvent) and event binding function (detachEvent) may not to use in practice, there are several reasons:

1.IE9 we will fully support the W3C event binding function;

2.IE event binding function cannot transfer this;

3.IE event binding function does not support capture;

4. with a number of registered letter binding, not blocked; 5. memory leak problem

you might be interested in this article:

This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:DOM event binding analysis in JS | Script Home

You may also be interested in these articles!