JavaScript events in a detailed

Source: Internet
Author: User

Event Flow

Describes the order in which events are received in a page

Event bubbling

Nodes that are received by the most specific element and then propagate up to the least specific element (document)

Event capture

The least specific node receives the event first, and the most specific node should be the last to receive the event

Event handling

HTML event Handling: Added directly to the HTML structure

DOM Level 0 Event handling: Assigning a function to an event handler property "will be overwritten"

The results will show 17 rows of results, and the previous lines of events will be overwritten. 18 line is the empty event.

DOM Level 2 event handling:

AddEventListener ("Event name", "event handler", "Boolean value")

True: Event Capture

False: Event bubbling

RemoveEventListener ()

Now, the Boolean value is no longer operational.

  

The result is demo1, which Demo3,demo4 executes sequentially and is not overwritten. The Demo2 is removed and will not be executed.

  

Not all browsers can handle 0-and 2-level events.

IE Event handlers

Attachevent

DetachEvent

Level 0 is more troublesome and will be overwritten.

Event Object

An object is generated when a DOM event is triggered

Events Object Event

1, type: Get event Type

2. Target: Get the event target

3. Stoppropagation (): Block event bubbling

4. Preventdefault (): Block event default behavior

JavaScript events in a detailed

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.