当前位置:网站首页>16.target和currenTarget的区别?
16.target和currenTarget的区别?
2022-07-21 11:38:00 【yingxingyf】
target:就是事件源
currentTarget:当前事件源(当前触发到哪个事件元素,那么这个事件元素就是事件源),跟this一样。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>作业5</title>
<style type="text/css">
#grandpaBox{
width:300px;
height:300px;
background-color:pink;
}
#fatherBox{
width:200px;
height:200px;
background-color:orange;
}
#meBox{
width:100px;
height:100px;
background-color:blue;
}
</style>
</head>
<body>
<div id="grandpaBox">
我是爷爷
<div id="fatherBox">
我是父亲
<div id="meBox">
我是div
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
//target:就是事件源
//currentTarget:当前事件源(当前触发到哪个事件元素,那么这个事件元素就是事件源),跟this一样。
$("meBox").addEventListener("click",function(event){
var evt = event || window.event;
console.log("我被点了,"+"target:"+evt.target.id+",currentTarget:"+evt.currentTarget.id);
console.log("this="+this.id);
},true);
$("fatherBox").addEventListener("click",function(event){
var evt = event || window.event;
console.log("爸爸被点了,"+"target:"+evt.target.id+",currentTarget:"+evt.currentTarget.id);
console.log("this="+this.id);
},true);
$("grandpaBox").addEventListener("click",function(event){
var evt = event || window.event;
console.log("爷爷被点了,"+"target:"+evt.target.id+",currentTarget:"+evt.currentTarget.id);
console.log("this="+this.id);
},true);
</script>
边栏推荐
- Basic principles and differences between countdownlatch and cyclicbarrier
- A tool that I hate to meet later, utools
- 基于ABP实现DDD--领域服务、应用服务和DTO实践
- Relative entropy, information entropy and cross entropy
- ionic4学习笔记4--新增一个tab页面
- Compile php7 to specify the Remi extension directory and the configuration directory of ini
- 论文阅读:DialoGPT
- Judge whether the binary tree is symmetric
- 基於ABP實現DDD--領域服務、應用服務和DTO實踐
- Wuxi launched a major investigation of potential food safety hazards in Pizza Hut stores in the city
猜你喜欢
Shell programming - functions
Relative entropy, information entropy and cross entropy
Determine whether binary search tree
EOS account system
基於ABP實現DDD--領域服務、應用服務和DTO實踐
残差网络解决了什么,为什么有效?—摘要
What does the residual network solve and why is it effective abstract
Summary of best practices for openfegin/restemplate microservice invocation
5.引用类型和值类型作为函数参数?
互联网大厂为何都爱“送外卖”?
随机推荐
libpng error: iTXt: chunk data is too large error: PNG unsigned integer out of range
13.onkeydown,up和onkeypress的区别?
Paper reading: a large scale Chinese short text conversation dataset (cdial GPT)
论文阅读:DialoGPT
Judge whether the binary tree is symmetric
libpng error: iTXt: chunk data is too large error: PNG unsigned integer out of range
Basic principles and differences between countdownlatch and cyclicbarrier
xxl-job(2.3.0)分布式任务bean模式,GLUE shell调度实践,源码debug
重入读写锁ReentrantReadWriteLock特性总结
使用sql批量修改MacOs照片应用(Photos)上的照片时间
Instant retail Three Kingdoms kill: meituan replenishment, Alibaba collaboration, jd.com drainage
水仙花数
Merge binary tree
2021-03-14-jwolf-temp-note
ionic4学习笔记6--在自定义组件中使用原生的ionic4组件
How to install Google play store in Xiaomi 10
epoch,batch_size
关于Hook unistd中open, read, write, close的一些技巧
The highest state of pulling wool, liberate your hands
Top understanding notes of LSTM