Home Web Front-end JS Tutorial js bubbling events and event listening usage analysis_javascript skills

js bubbling events and event listening usage analysis_javascript skills

May 16, 2016 pm 06:45 PM
event listening bubbling event

Bubble event
"Bubble event (bubble)" in js is not a fancy trick that can be used in practice. It is a mechanism for executing the sequence of js events. "Bubble algorithm" is a classic problem in programming. The "bubble" in the bubble algorithm should be said to be exchange more accurately; the "bubble event" in js is the true meaning of "bubble". It traverses the tree layer by layer from the lowest level of the DOM, and then attaches the corresponding events. Take the following code as an example:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

View the running effect
Event monitoring
To be precise, event monitoring can be said to be the operation of the js engine to monitor the user's mouse, keyboard, window events and other actions, that is, to attach events to the user's corresponding operations. Commonly used ones are similar to btnAdd.onclick=" alert('51obj.cn')" is a simple attached event, but this method does not support attaching multiple events and deleting events. The following code will implement deletion of events after attaching events (under IE):
Click
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

View the running results
IE cannot be called a standard DOM browser. Even the latest IE8 is a "heterogeneous" compared to standard DOM such as Firefox, Opera, etc.; only in Firefox does there really exist a function called event listening function addEventListener, as shown in the following example
Click
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
View the running effect
www.jb51.net»»
[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute ]
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What events cannot bubble up? What events cannot bubble up? Nov 20, 2023 pm 03:00 PM

What events cannot bubble up?

Implement map event monitoring function using JavaScript and Tencent Maps Implement map event monitoring function using JavaScript and Tencent Maps Nov 21, 2023 pm 04:10 PM

Implement map event monitoring function using JavaScript and Tencent Maps

Why do events fail to bubble up? Why do events fail to bubble up? Jan 13, 2024 am 08:50 AM

Why do events fail to bubble up?

No support for bubbling events: limitations and scope No support for bubbling events: limitations and scope Jan 13, 2024 pm 12:51 PM

No support for bubbling events: limitations and scope

How to effectively prevent events from bubbling up How to effectively prevent events from bubbling up Feb 19, 2024 pm 08:25 PM

How to effectively prevent events from bubbling up

Master the common event bubbling mechanism in JavaScript Master the common event bubbling mechanism in JavaScript Feb 19, 2024 pm 04:43 PM

Master the common event bubbling mechanism in JavaScript

Master the importance of bubbling events and enhance personal social skills Master the importance of bubbling events and enhance personal social skills Jan 13, 2024 pm 02:22 PM

Master the importance of bubbling events and enhance personal social skills

What is the meaning of bubbling events What is the meaning of bubbling events Feb 19, 2024 am 11:53 AM

What is the meaning of bubbling events

See all articles