Home > Web Front-end > JS Tutorial > body text

js bubbling events and event listening usage analysis_javascript skills

WBOY
Release: 2016-05-16 18:45:58
Original
838 people have browsed it

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 ]
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template