201510091346_ "JavaScript event model--createevent, Initevent, dispatchevent"

Source: Internet
Author: User

1. There are three event models: the original event model (supported by all browsers), the DOM2 (supported by browsers except IE), the event model, the IE event model, and the Netscape event model.

--------------------------------------------------------------------------------------------------------------- --------------------------------

2. Detailed model

(1) Original event model

Divided into: Semantic event onclick and input event onsubmit

-------------------------------------------------------------------------

(2) DOM2 event model

It is generally divided into three steps: 1) The document is first propagated to the target object called the capture phase; 2) The event handler of the target object runs, and 3) bubbles from the target object to the document. Event.stoppropagation () can stop propagation, Preventdefault can block the default action of an event

AddEventListener ("EventType", "handler", "true!false"); //true, called at the stage of snapping; false, in the latter two stages;

Removeeventlistner ("EventType", "handler", "True!false");

Event compositing

1) Create the appropriate event object:

var e=document.createevent ("Htmlevents");

2) Initialize Event object domain (ie: attribute)

E.initevent ("Click", "true", "true");

3) Assign the event object:

Eventtarget.dispatchevent (); -------------------------------------------------------------------------

(3) IE Event Model

IE Event object also has, but only a property of window, the target element's handler function--〉document, can only capture mouse events; event handlers are added and removed by: attachevent ("Eventty PE "," Handler ") and DetachEvent (" EventType "," handler ");

Indow.ecent.cancelbubble=true;

Event Registration functions: attachevent () and anti-registration: DetachEvent ().

-------------------------------------------------------------------------

(4) Netscape Event Model

--------------------------------------------------------------------------------------------------------------- --------------------------------

3.

201510091346_ "JavaScript event model--createevent, Initevent, dispatchevent"

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.