当前位置:网站首页>Event object learning
Event object learning
2022-07-21 18:29:00 【Hugging spinner】
One . What is an event object
Official explanation : event Object represents the state of the event , For example, the state of keyboard keys 、 Mouse position 、 Mouse button status .
Simple understanding ∶ After the event , A collection of information data related to an event Put them all in this object , This object is It's the object of the event event, It has many properties and methods .
Event object compatibility scheme
There is a compatibility problem with the acquisition of the event object itself :
1. In the standard browser, the parameters passed by the browser to the method , Just define the formal parameters e I can get it .
2. stay IE6~8 in , The browser does not pass parameters to methods , If necessary , Need to window.event To find .
solve :
e = e ll window.event;
Two . Common properties and methods of event objects
Properties and methods of common event objects
e.target and this The difference between
e.target The object that triggers the event is returned ( Elements )
this What is returned is the object that binds the event ( Elements )
difference :e.target Click on that element , Just return that element this, That element binds the click event , Then return to who
Understand compatibility issues
3、 ... and . Blocking default behavior
dom Standard writing :e.preventDefault();
Lower version browser ie678 :returnValue attribute
Four . To prevent a bubble
Event Bubbling ∶ It starts with the most specific element , Then spread up to DOM Top node .
Two ways to stop bubbling
1. Standard writing : Use the... In the event object stopPropagation() Method (stop stop it Propagation spread )
2. Nonstandard writing :IE6-8 Use event objects cancelBubble attribute
e.cancelBubble = true ( Nonstandard cancel Cancel bubble Bubble )
Compatibility solution to prevent event bubbling
Example :
5、 ... and . Event delegation
Event delegates are also called event proxies , stay jQuery It's called event delegation .
principle :
Not every child node sets up an event listener alone , Instead, the event listener is set on its parent node , Then use the bubble principle to influence the setting of each child node .
The above cases : to ul Register click events , Then use the... Of the event object target To find the currently clicked li, Because click li, Events will bubble to u On ,u There are registration events , The event listener is triggered .
effect :
We only operated once DOM, Improved program performance .
Example :
边栏推荐
- golang拾遗:自定义类型和方法集
- Under the wave of infotnews | meta universe, enterprises are improving customer experience through AR and VR technologies
- Les enregistrements d'une période de temps sont interrogés dans la base de données Oracle. S'il n'y a pas d'enregistrements d'un jour donné, les enregistrements du dernier jour seront remplis. Comment
- 高性能服务器模型总结
- 【IoT毕设.1】esp8266+机智云AIoT+猪舍监测系统设计与实现
- pytorch-California House Prices
- About dynamic setting text of label and button in swing interface
- Oracle數據庫中查詢一個時間段內的記錄,如果其中某一天的記錄沒有,則取最近一天的記錄填充,這個SQL應該怎麼寫呢?
- EasyNVS定制项目中的播放器更新及相应新功能增加
- Installation and use tutorial of labelimg (object detection and annotation tool)
猜你喜欢
Tiktok system | huge arithmetic interface signature analysis and decryption
Master the wonderful use of dowanward API and easily grasp kubernetes environment variables
基于ssm框架的大学生社团管理系统
Double disk: intelligent cockpit series article 6 - its three interactive ways of explicit interaction (voice and display)
Rxjs see the moon JS special effect code through the window
Using zdog to realize JS special effect of outlook lighthouse animation
羧甲基荧光素6-FAM修饰PNA肽核酸6-FAM-PNA|CY3-PNA荧光染料CY3偶联PNA肽核酸的应用
Appium automated testing
Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
Resume: intelligent cockpit series article 5 - implicit interaction of its three interaction modes
随机推荐
MySQL between syntax
page-break-before和page-break-after 实现分页打印
ant. The date selection of rangepicker in time datepicker in design (antd for short) is limited to the date before 0 o'clock of a certain day
Niuke-top101-bm34
On the differences and advantages of project compilation tools ninja, make and cmake
Under the wave of infotnews | meta universe, enterprises are improving customer experience through AR and VR technologies
What functions does the application of object recognition table have
CY5-PNA花菁染料CY5标记肽核酸PNA的实验要求
PHP 给数组增加数据(array_unshift、array_push、array_splice、array_pad)
Ag掺杂改性金属有机骨架多孔材料MIL-101|核壳结构的[email protected]催化剂([e
Mogdb installation
写代码将三个整数数按从大到小输出。
一文读懂 MongoDB 和 MySQL 的差异
Network Security Learning (Qianfeng network security notes) 3 -- batch preparation
Tiktok system | huge arithmetic interface signature analysis and decryption
High performance server model summary
VS2017监视窗口
Don't know how to learn MySQL? It's enough to finish the 50 questions of Niuke! (Part VII)
目标检测 | 基于统计自适应线性回归的目标尺寸预测
利用社区结构可视化复杂网络