当前位置:网站首页>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 .
边栏推荐
- Do it yourself container
- ES6新特性(入门)
- LVM与磁盘配额
- Keras OCR instance test
- Li Hongyi 2020 deep learning and human language processing dlhlp conditional generation by RNN and attention-p22
- Use -wall to clear code hidden dangers
- Boostrap
- Go language learning
- Record of pychart running jupyter notebook in virtual environment
- 网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
猜你喜欢

云原生运行环境搭建

FTX US推出FTX Stocks,向主流金融行业迈进

For redis under windows, it can only read but not write

Esxi virtual machine starts, and the module "monitorloop" fails to power on

Linux安装与卸载MySql

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

What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!

众多世界500强企业集聚第二届数博会,数字产业大幕即将开启!

3D打印品牌的康复骨科支具有何特别之处?

What is the reason why dragging the timeline is invalid when playing device videos on the easycvr platform?
随机推荐
Project training experience 2
Go语言学习
Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
Rsync remote synchronization
网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
deepsort源码解读(四)
Introduction to the official functions of easyrecovery14 data recovery software
Log in to Alibaba cloud server with a key
EasyRecovery14数据恢复软件官方功能简介
PXE efficient batch network installation
shell常用命令-备忘录
pycharm在虚拟环境下跑jupyter notebook问题记录
MySql数据库
ESXI虚拟机启动,模块“MonitorLoop”打开电源失败
2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!
Ancient art - make good use of long tail keywords
Soul持续发力社交渠道赴港上市,“Soul式社交”凭什么火出圈?
A cross domain problem of golang
2022年全球最具技术实力的的智能合约安全审计公司推荐
一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告诉你一键修复漏洞可行吗?向日葵来告