当前位置:网站首页>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 .
边栏推荐
- FTX.US推出股票和ETF交易服务,让交易更透明
- EasyRecovery14数据恢复软件官方功能简介
- PSI | CSI and ROC | AUC and KS - memorandum
- 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
- Recommended by the world's most technologically competent smart contract security audit company in 2022
- Future, futuretask and completable future are often asked in interviews
- pycharm在虚拟环境下跑jupyter notebook问题记录
- Shell script one click configuration lamp
- To improve the baby's allergy, take yiminshu. Azg and aibeca love la Beijia work together to protect the growth of Chinese babies
- torch加载自定义模型的问题
猜你喜欢

ESXI虚拟机启动,模块“MonitorLoop”打开电源失败

Sunflower popularizes Science in an all-round way to avoid loopholes for your remote control equipment in time

Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform

向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解

一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告

Px4 source code compilation to establish its own program module

Deepsort工作原理分析

ES6的新特性(2)

向日葵教大家如何防范拒绝服务攻击漏洞?
![Summary of frequently asked questions in the interview [summarized after painstaking work all night]](/img/70/90543c23326305590242716b989643.png)
Summary of frequently asked questions in the interview [summarized after painstaking work all night]
随机推荐
After adding a camera (camera) to the UAV in gazebo, the UAV cannot take off
Fix the problem that the paging data is not displayed when searching the easycvr device management list page
Deepsort工作原理分析
LVM and disk quota
FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health
deepsort源码解读(三)
Shell common commands - memos
According to SQL, you must know and learn SQL (MySQL)
3D打印品牌的康复骨科支具有何特别之处?
程序、进程、线程、协程以及单线程、多线程基本概念
众多世界500强企业集聚第二届数博会,数字产业大幕即将开启!
GoLand 编写go程序
shell常用命令-备忘录
goLang的一个跨域问题
System security and Application
Px4 source code compilation to establish its own program module
Recommended by the world's most technologically competent smart contract security audit company in 2022
Create a container that does not depend on any underlying image
FTP service introduction and configuration
DNS domain name resolution service