当前位置:网站首页>Event capture and bubbling - what is the difference between them?
Event capture and bubbling - what is the difference between them?
2022-07-27 06:54:00 【THER1881】
Event Bubbling 、 Capture : Event bubbling and event capture were proposed by Microsoft and Netscape respectively , Both of these concepts are designed to solve the problem of event flow in a page ( Sequence of events ) The problem of .
1、 Event Bubbling
Microsoft came up with an event stream called event bubble . Structurally ( Not visually ) Elements of nested relationships , There will be bubble function , The same thing , Bubbling from child to parent .( Bottom up )
Then let's verify it :
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 200px;
height: 100px;
background-color: red;
text-align: center;
line-height: 100px;
cursor: pointer;
}
</style>
<body>
<div> Click on </div>
<script>
let body = document.querySelector('body')
let div = document.querySelector('div')
body.addEventListener('click',function(){
console.log('body')
})
div.addEventListener('click',function(){
console.log('1')
})
</script>
</body>

2、 Event capture
Structurally ( Not visually ) Elements of nested relationships , There will be event capture capabilities , The same thing , From parent to child ( Event source element ).( The top-down )(ie No capture events )
Then let's verify it :
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 200px;
height: 100px;
background-color: red;
text-align: center;
line-height: 100px;
cursor: pointer;
}
</style>
<body>
<div> Click on </div>
<script>
let body = document.querySelector('body')
let div = document.querySelector('div')
body.addEventListener('click',function(){
console.log('body')
},ture)
div.addEventListener('click',function(){
console.log('1')
},ture)
</script>
</body>

difference
Event Bubbling : One from the inside out , Bubbling , Extend to the upper level .
Event capture : One from the outside to the inside , Go to capture , Form a downward trend .
边栏推荐
- Common font and color settings of markdown documents
- Many of the world's top 500 enterprises gathered at the second digital Expo, and the digital industry curtain is about to open!
- Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
- Sunflower popularizes Science in an all-round way to avoid loopholes for your remote control equipment in time
- According to SQL, you must know and learn SQL (MySQL)
- A cross domain problem of golang
- 多模态数据库 | 星环科技多模数据库ArgoDB“一库多用“,构建高性能湖仓集一体平台
- EasyRecovery14数据恢复软件官方功能简介
- Express框架
- Add virtual network card and configure OP route in win10
猜你喜欢

Detection and identification data set and yolov5 model of helmet reflective clothing

Redis operation of Linux Installation

如何避免漏洞?向日葵远程为你讲解不同场景下的安全使用方法

How to avoid loopholes? Sunflower remote explains the safe use methods in different scenarios

关于卡尔曼滤波的协方差如何影响deepsort的跟踪效果的考虑

Inventory of the world's six most technologically competent smart contract audit companies in 2022

Is it feasible to fix the vulnerability with one click? Sunflower to tell you that one click fix vulnerability is feasible? Sunflower to tell you that one click fix vulnerability is feasible? Sunflowe

ES6新特性(入门)

如何删除或替换EasyPlayer流媒体播放器的loading样式?

FTX US推出FTX Stocks,向主流金融行业迈进
随机推荐
Shell script delete automatically clean up files that exceed the size
Concept and principle of DHCP
Disk management and file system
Redis' idea under windows is not connected
Express接收请求参数
磁盘管理与文件系统
Build cloud native operating environment
Tips - completely delete the files on the USB flash drive
如何让最小 API 绑定查询字符串中的数组
Some problems about too fast s verification code
Use -wall to clear code hidden dangers
Account management and authority
Record of pychart running jupyter notebook in virtual environment
网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
Boostrap
Pruning - quantification - turn to onnx Chinese series tutorials
Packaging of logging logs
Sunflower teaches you how to prevent denial of service attacks?
What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
PSI|CSI和ROC|AUC和KS -备忘录