当前位置:网站首页>DOM event flow
DOM event flow
2022-07-25 04:01:00 【Like the rising sun】
List of articles
DOM The event flow describes DOM The stage of time response 、 route .
1. Event flow phase
There are three stages of event flow , They are as follows :
1.1 Capture phase
from window Start , Find the deepest node that triggers the event , In the process, if a node is bound to the corresponding event , The event is triggered
1.2 Target stage
Find the deepest node touched by the event
1.3 bubbling phase
Return from the deepest node according to the captured path , In the process, if a node is bound to the corresponding event , The event is triggered
for instance
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>gnn</title>
</head>
<body>
<style> .box {
display: flex; align-items: center; justify-content: center; } .size-100 {
width: 100px; height: 100px; background: #5653e4; } .size-200 {
width: 200px; height: 200px; background: rgb(168, 166, 165); } .size-300 {
width: 300px; height: 300px; background: rgb(251, 251, 251); } </style>
<div class="box size-300">
<div class="box size-200">
<div class="box size-100">
</div>
</div>
</div>
<div class="result"></div>
<script> var boxes = document.querySelectorAll('.box'); var result = document.querySelector('.result'); boxes.forEach(function (box) {
box.addEventListener('click', function () {
var el = document.createElement('p'); el.innerText = ' Now what triggers the click event is ' + this.className; result.appendChild(el); }); }); </script>
</body>
</html>
Click the blue area in the middle to find that the event is executed upward by the deepest node you click , Here's the picture

From size-100 To size-200 To size-300, This is the process of bubbling .
If you want the event to execute in the capture phase , It can deliver addEventListener The third parameter in the method . Let's talk about it addEventListener Method
2. addEventListener Three parameters of
Use element.addEventListener You can bind multiple event handlers , Let's introduce the parameter values of this method
2.1 event
must . character string , Specify time name
Be careful : Do not use “on” Prefix . for example , Use “click” , instead of “onClick”
2.2 function
must . Specifies the function to be executed when the event is triggered .
When the event object is passed into the function as the first parameter . The type of event object depends on the specific event .
2.3 useCapture
Optional , Boolean value , Specifies whether the event is executed during the capture or bubble phase .
· false Default : The handler executes in the bubbling phase .
· true : The handler executes during the capture phase .
3. Summary
The development process rarely takes the stage triggered by change events . But the concept of event flow is still important , Because many times we have to stop the event from bubbling .
边栏推荐
- Project launch process of software testing technology
- Homologous strategy, surface longitude
- The sixth day of brushing questions with force deduction
- Digital collections can go further without hype
- Fifth day of force deduction
- Chapter 3 business function development (modify the remarks of market activities)
- LeetCode. 302 weekly games___ 03_ 6121. Query the number smaller than k after cutting the number____ sort
- 01_ Education 1
- 应急响应全栈
- Execution flow control of shell
猜你喜欢

Xrrunner, a domestic performance testing tool for palm smart, officially unveiled qecon

使用 “display: flex;justify-content: center;align-items: center; ” 解决流式栅格布局无法居中的问题

Wechat applet access wechat payment process

Cluster clock synchronization configuration

What are the models of asemi from the manufacturer of rectifier bridge and how about the electroplating process of the manufacturer of rectifier bridge?

应急响应全栈

.net6 miniapi (V): Options

Execution flow control of shell

数据中台建设(一):数据中台出现的背景

Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
随机推荐
Wechat applet access wechat payment process
Server status code
NC | progress has been made in the study of the ecological network relationship between dissolved organic carbon and microorganisms in the context of global change
Force deduction brush question 7. Integer inversion
Debezium series: in depth interpretation of important JMX indicators of debezium
Emergency response stack
Localization distillation for dense object detection cvpr2022
Network security - comprehensive penetration test -cve-2018-10933-libssh maintain access
Installation and tutorial of MATLAB curling simulation game
JS absolute minimum value of the sum of Huawei od two numbers
CVPR 2022 | content aware text logo image generation method
Implementing DDD based on ABP -- domain logic and application logic
Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
Es- retrieve the selected field from the search
Force deduction question 3
01_ Education 1
Solve "nothing added to commit but untracked files present"“
Imeta | ggclusternet microbial network analysis and visualization nanny level tutorial
Memory leak due to improper handling of custom view
You are only one SQL statement away from the tdengine Developer Conference!