当前位置:网站首页>e.target与e.currentTarget的区别
e.target与e.currentTarget的区别
2022-07-27 03:34:00 【尼克_张】
<div id="big" class="big">
<div id="middle" class="middle">
</div>
</div>
.big {
background: red;
height: 50vh;
width: 50vh;
}
.middle {
background: green;
height: 30vh;
width: 30vh;
}
addEventListener的第三个参数表示是否捕获,默认为false
true表示执行捕获(由外向内)
false表示执行冒泡(由内向外)
1.执行冒泡
big.addEventListener('click', function (e) {
console.log("big--", "currentTarget:",e.currentTarget, "target:",e.target)
}, false)

middle.addEventListener('click', function (e) {
console.log("middle--", "currentTarget:",e.currentTarget, "target:",e.target)
}, false)

2.执行捕获
big.addEventListener('click', function (e) {
console.log("big--", "currentTarget:",e.currentTarget, "target:",e.target)
}, true)

middle.addEventListener('click', function (e) {
console.log("middle--", "currentTarget:",e.currentTarget, "target:",e.target)
}, true)

3.总结
target:触发事件的元素
currentTarget:事件绑定的元素
当点击父元素时,两者指向的是同一个元素。
当点击子元素时,父元素的事件也会触发,此时父元素事件的currentTarget指向父元素,target指向子元素,执行顺序为冒泡(父——子),捕获(子——父)。
边栏推荐
- DINO 论文精度,并解析其模型结构 & DETR 的变体
- Elastic open source community: Developer Recruitment
- 微信input组件添加清除图标,点击清空不生效
- Subject 3: Jinan Zhangqiu line 3
- Maximum nesting depth of parentheses
- Plato Farm全新玩法,套利ePLATO稳获超高收益
- Project time zone problem solving
- 【机器学习网络】BP神经网络与深度学习-6 深度神经网络(deep neural Networks DNN)
- Subject 3: Jinan Zhangqiu line 5
- What is animation effect? What is the transition effect?
猜你喜欢

Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!

Framework learning journey: init process startup process

Ant JD Sina 10 architects 424 page masterpiece in-depth distributed cache from principle to practice pdf

452页13万字现代智慧乡镇雪亮工程整体解决方案2022版

356 pages, 140000 words, weak current intelligent system of high-end commercial office complex, 2022 Edition

Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice

Lixia action | Yuanqi Digitalization: existing mode or open source innovation?

三种常见的移动底盘运动学模型分析

Restful fast request 2022.2.2 release, supporting batch export of documents

Golang sends email to the mail Library
随机推荐
Internet of things smart home project - Smart bedroom
链表内指定区间反转
第二轮Okaleido Tiger即将登录Binance NFT,或持续创造销售神绩
Five basic data structures of redis
【MySQL系列】MySQL索引事务
通信协议综述
[competition reference] pytorch common code snippet and operation collection
influxDB 基础了解
Nonlinear optimal tracking control based on wind energy conversion system (realized by matlab code)
Navicat exports Mysql to table structure and field description
288 page 180000 word intelligent campus overall design directory
Is VR panorama just needed now? After reading it, you will understand
php+swoole
Leetcode:433. minimal genetic change
微服务化解决文库下载业务问题实践
Rust:axum learning notes (1) Hello World
Practice of microservice in solving Library Download business problems
scala 不可变Map 、 可变Map 、Map转换为其他数据类型
Restful fast request 2022.2.2 release, supporting batch export of documents
Golang sends email to the mail Library