当前位置:网站首页>DOM operation of JS -- event object
DOM operation of JS -- event object
2022-07-20 06:38:00 【M78_ Domestic 007】
Event triggered ,handler Data will be passed in the function , This data is the event object .
There are three ways to bind events , In line binding 、 Attribute binding 、 Listener binding .
Where is the intra row binding , Cannot get event object in line ; Property binding and listener binding , The event object is in the parameter .
So how to solve the problem that events cannot be obtained in the line ?
We use compatible writing , No matter which method triggers , Let's judge the parameters first e,
e=(e.constructor==PointerEvent&&e)||window.event// Compatible writing
Code display :
<div class=".test" onclick="fn1()">
111
</div>
<script>
function fn1(e){
e=(e.constructor==PointerEvent&&e)||window.event// Compatible writing
console.log(e);
}
</script>
Print the results :
Show me how to get event objects when Binding attributes and listeners :
<div class="boxx">111</div>
<script>
var boxx=document.querySelector(".boxx")
boxx.onclick=function(e){
console.log(e);
}
boxx.addEventListener("click",function(e){
console.log(e);
})
</script>
The running results are visible , Event triggered , The generated data will be passed into the processing function , This data is exactly the event object we need .
We also need to know about this:
In intra row binding : The caller of the function is window
In property binding :this Pointing to dom The element itself
In the listener binding :this Pointing to dom The element itself
边栏推荐
- User defined MVC addition, deletion, modification and query
- NahamCon CTF 2022 Babyrev逆向分析
- [C exercise] arrow pattern
- 深入理解ArrayList
- 靶机无法获得IP地址, 该怎么办?
- [depth] the new LAAS agreement elephant: the key to revitalizing the development of the defi track
- 防电子墨水屏ST7302
- Shell query Prometheus data
- JVM知识图谱(更新中)
- 五行八卦的学问
猜你喜欢
亲测五种高效实用的脱单方法,赶紧收藏帮你快速找到优质对象!
WTO officially announced that sun Yuchen's MC12 speech covered major topics such as e-commerce
MySQL string operation (substr interception, locate instr position child parent string judgment)
VLAN聚合
ES6-Set和Map
JS的DOM操作——事件
每日刷题记录 (二十七)
个人开发的解ctf usb的键盘流量的工具 KeyboardTraffic
Leetcode- supplementary question 6 - sorting by hand
[Development Tutorial 4] crazy shell arm function mobile phone - development interface connection tutorial
随机推荐
[Niuke brush questions] / * daily four programming questions to share*/
Qianshi application | SRT Internet transmission technology program successfully assisted the "Jiangxi emergency · 2022" comprehensive drill
【快速上手教程1】疯壳·开源编队无人机-开机测试
J9数字货币平台科普:Sui网络的双共识是如何工作的?
arguments.callee的用法
J9 digital currency platform popular science: how does the double consensus of Sui network work?
Solution to expiration of visual studio tomato plug-in -- continue to resume trial
[Web3 series development tutorial - create your first NFT (3)] start to create NFT
Time flies.
[self learning] - how to make the dialogue robot stronger and stronger?
JS的DOM操作——事件
华为虚拟化FusionCompute知识点总结
View的measure测量过程梳理
关于引导的作用
“蜂聚惠”电商购物平台线上线下齐发力,打造全域电商新秀崛起
Shell query Prometheus data
Ali test engineer's words will save you ten years of detours
企业内容管理(ECM)与文档管理的区别及其优势
ovirt: api
Award winning research | what does the perfect ar development platform look like to make virtual reality?