当前位置:网站首页>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指向子元素,执行顺序为冒泡(父——子),捕获(子——父)。
边栏推荐
- 三种常见的移动底盘运动学模型分析
- xxx is not in the sudoers file. This incident will be reported
- 【OBS】circlebuf
- Internet of things smart home project - Smart bedroom
- Cool Lehman VR panorama paves the way for you to start a business
- Subject 3: Jinan Zhangqiu line 5
- JMeter interface test (login, registration)
- Use tag tag in golang structure
- Project time zone problem solving
- Lixia action | Yuanqi Digitalization: existing mode or open source innovation?
猜你喜欢

"Gonna be right" digital collection is now on sale! Feel the spiritual resonance of artists

tcp协议知识详解

288 page 180000 word intelligent campus overall design directory

2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作

452 pages, 130000 words, the overall solution of modern smart Township Xueliang project 2022 Edition

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

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

JVM原理简介

Brightcove任命Dan Freund为首席营收官

Five basic data structures of redis
随机推荐
Ant JD Sina 10 architects 424 page masterpiece in-depth distributed cache from principle to practice pdf
Brightcove任命Dan Freund为首席营收官
Leetcode:433. minimal genetic change
scala 不可变Map 、 可变Map 、Map转换为其他数据类型
php+swoole
BigDecimal踩坑总结&最佳实践
[semidrive source code analysis] [drive bringup] 41 - LCM drive backlight backlight control principle analysis
Elastic open source community: Developer Recruitment
Cool Lehman VR panorama paves the way for you to start a business
Subject 3: Jinan Zhangqiu line 2
Elastic开源社区:开发者招募
288 page 180000 word intelligent campus overall design directory
EVT interface definition file of spicy
ffmpeg合并视频功能
Navicat exports Mysql to table structure and field description
[OBS] dynamic bit rate: bit rate estimation
c# 获取uuid
JMeter interface test (login, registration)
[competition reference] pytorch common code snippet and operation collection
452页13万字现代智慧乡镇雪亮工程整体解决方案2022版