当前位置:网站首页>Description of event flow
Description of event flow
2022-06-30 09:56:00 【zimingyo】
Event flow and two-stage description
Flow of events : It refers to the flow path during the complete execution of the event
Two phases : Capture phase ( Father to son ) And bubbling stage ( Son to father )
Event capture and event bubbling
Event Bubbling
- Concept : When an element's event is triggered , The same event will be triggered in turn in all the ancestor elements of the element .
- Simple understanding : When an element triggers an event , All parent elements will be called up in turn Events of the same name ( It means that the trigger event type is the same : A fellow click)
- Event bubbling exists by default
Event capture - Concept : from DOM The root element of starts to execute the corresponding event ( From the outside to the inside )
- Event capture needs to write corresponding code to see the effect
- Code
DOM.addEventListener( Event type , Event handler , Whether to use capture mechanism ) - explain :
addEventListener The third parameter is passed in true The capture phase triggers when representing ( Rarely used )
If the incoming false Indicates that the bubbling phase triggers , The default is false
If used L0 Event monitoring , Then there is only the bubbling stage , No capture
Stop the flow of events
- Because there is a bubble mode by default , Therefore, it is easy for events to affect parent elements
- If you want to limit the event to the current element , You need to stop the flow of events
- To stop the flow of events, you need to get the event object
- grammar :
Event object .stopPropagation() - This method can block the flow and propagation of events , Not just in the bubbling phase , The capture phase is also effective .
Mouse over event :
- mouseover and mouseout There will be bubbling effect
- mouseenter and mouseleave No bubbling effect
Blocking default behavior : For example, clicking a link does not jump , Form field cannot be submitted
grammar :e.preventDefault()
The difference between the two registration Events
Tradition on register (L0)
bt.οnclick=function(){}
- Same object , The events registered later will overwrite the events registered earlier
<body>
<button> Click on </button>
<script> let bt=document.queryselect('button') bt.onclick=function(){
alter(11) } bt.onclick=function(){
alter(12) } // The execution result is 12 </script>
</body>
- Use it directly null The event can be unbound by overwriting
bt.οnclick=null
- It's all performed in the bubbling phase
Event listening registration (L2)
bt.addEventListener('click',function(){})
bt.addEventListener(‘click’, Function name )
function Function name (){}
- grammar :addEventListener( Event type , Event handler , Whether to use capture ) [true It's capture ,false It's bubbling ( Default )]
- The events registered later will not overwrite the events registered earlier ( The same thing )
- The third parameter can be used to determine whether it is in the bubble or capture phase
- You have to use removeEventListener( Event type , Event handler , Whether to use capture )
bt.addEventListener('click',add)
function add(){
alter(35)
}
bt.removeEventListener('click',add)
// Can't get 35
- Anonymous functions cannot be unbound ( For the second form )
边栏推荐
- Flume learning 4
- 训练一个图像分类器demo in PyTorch【学习笔记】
- thrift简单使用
- JVM notes (III): analysis of JVM object creation and memory allocation mechanism
- MySQL internal component structure
- Abstract classes and interfaces
- tf. keras. layers. Attention understanding summary
- Network based BGP
- Brève description du collecteur d'ordures G1
- oracle跨数据库复制数据表-dblink
猜你喜欢

Techtarget: Interpretation of the basic concept of super fusion cloud

Differences and relationships among hyper convergence, software defined storage (SDS), distributed storage and server San

About the smart platform solution for business hall Terminal Desktop System

安装和使用
![[new book recommendation] mongodb performance tuning](/img/2c/e5a814df4412a246c703ca548a4f68.png)
[new book recommendation] mongodb performance tuning

直播带货源码开发中,如何降低直播中的延迟?

单片机 MCU 固件打包脚本软件

Network based dynamic routing protocol (OSPF)

JVM garbage collector G1 & ZGC details

9.缓存优化
随机推荐
3. integrate eslint and prettier
Comparison problems encountered in recent study
Bluetooth BT RF test (forwarding)
1, 基本配置
无人机项目跟踪记录八十三---pcb图完成
Practice of super integration and transformation of core production business of public funds
Task summary in NLP
JWT expiration processing - single token scheme
JVM notes (III): analysis of JVM object creation and memory allocation mechanism
ABAP-时间函数
Follow the wechat oauth2.0 access scheme
P. Summary of NP, NPC, NP hard and other issues
Add / delete query of topic
Redis docker master-slave mode and sentinel
Object detection yolov5 open source project debugging
鼠标右键打开cmd(命令行)
MySQL优化
浏览器复制的网址粘贴到文档是超链接
机械臂速成小指南(五):末端执行器
11. customize hooks