JS Event Delegate

Source: Internet
Author: User

One, what is an event delegate?

When it comes to event delegation, the event mechanism of JavaScript is first mentioned.

In JS, it is divided into DOM level 0 events and DOM Level 2 events.

Let's see what is a dom0 level event:

The disadvantage of DOM level 0 events is that events written after you bind multiple events to an object overwrite the first-written event

The following are the DOM2 level events:

DOM Level 2 Events:

AddEventListener (' Event type ', function name , true/false);

Parameter 1: Event type does not need to be added on

Parameter 2: callback function

Parameter 3:true means capture Dalse represents capture

How to Unbind an event:RemoveEventListener ()

IE's DOM2 level event:

Attachevent ()

Parameter 1: Event type needs to be added on

Parameter 2: callback function

Unbind Event Method:detachevent ();

Event Flow: when an HTML element produces an event , the event propagates through the path between the element node and the root node, and the node that passes through the path receives the event, which is called the DOM event stream

Bubbling event: Microsoft raises the event that a child element is passed to the parent element, called bubbling

Capture event: The process by which Netscape presents an event passed by a parent element to a child element, called event capture

The event was finally entrusted:

Event delegation: Using the principle of event bubbling, the parent is used to trigger the event of the child.

Event object: An object represents the state of an event, such as the element in which the event occurred, the state of the keyboard key, the position of the mouse, the state of the mouse button

Event delegate:

Gets the compatible wording of the event object:

Btn.click = function (e) {

var e = e| | Event

}

Get Targe His compatible wording:

var target = e.target| | E.srctarget;

JS Event Delegate

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.