当前位置:网站首页>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 .
边栏推荐
- ES6新特性(入门)
- 如何避免漏洞?向日葵远程为你讲解不同场景下的安全使用方法
- Linux安装与卸载MySql
- Redis快速学习
- DNS domain name resolution service
- 向日葵教大家如何防范拒绝服务攻击漏洞?
- Raid explanation and configuration
- Build cloud native operating environment
- What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
- What is the reason why dragging the timeline is invalid when playing device videos on the easycvr platform?
猜你喜欢

Sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then judge sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then ju

Linux安装与卸载MySql

C语言怎么学?这篇文章给你完整答案

Redis快速学习

DNS domain name resolution service

keras-ocr实例测试

Soul 递交港股上市申请,加快社交聚集地多元化、场景化的布局

LVM与磁盘配额

向日葵教大家如何防范拒绝服务攻击漏洞?

Project training experience 1
随机推荐
KVM command set management virtual machine
shell常用命令-备忘录
deepsort源码解读(四)
How to avoid loopholes? Sunflower remote explains the safe use methods in different scenarios
Create a container that does not depend on any underlying image
Use -wall to clear code hidden dangers
Shell common commands - memos
According to SQL, you must know and learn SQL (MySQL)
Alibaba cloud SMS authentication third-party interface (fast use)
Soul continues to make efforts to list its social channels in Hong Kong. Why is "soul style social" popular?
keras-ocr实例测试
deepsort源码解读(五)
客户案例 | 聚焦流程体验,助银行企业APP迭代
Redis operation of Linux Installation
The difference between malloc and new - Practical chapter
ES6 new features (getting started)
自己动手实现容器
Recommended by the world's most technologically competent smart contract security audit company in 2022
Pymysql query result conversion JSON
Express框架