当前位置:网站首页>Day32 JS note event (Part 1) September 27, 2021
Day32 JS note event (Part 1) September 27, 2021
2022-06-28 11:31:00 【Little dream of becoming a big man】
Three elements of the event : Event binding 、 Event type 、 Event function
Common handling :
1. On the label or js In file dom Elements . event = function(){}
2.function fn(){} dom Elements .onclick = fn
- Do not add parentheses after the function name Call and execute by yourself
Be careful : Don't give... When submitting forms form Form binding click event , The form will be submitted by default After submitting, it is equivalent to refreshing the page and jumping to a new page In the form submit Method
Flow of events :
- Capture phase : Start from the outermost layer of the code and look for the inner layer of the code , Is a process of finding binding events ( From the outside to the inside )
- Target stage : Reach the location of the target event Triggering event
- bubbling phase : From the target event to html Go back to the document again ( From the inner layer to the outer layer ) Browser default Events !!
Event binding : The previous method of using event binding is on+ Event type This method can be used, but in special cases there are bug Of
- Events of the same type Bound to a tag Will appear bug The back covers the front
Monitor / The listener
grammar : dom Elements .addEventListener(' No addition on The type of event ', Event handler function(){
// Code snippet executed
}, Whether to execute in the capture phase - What is commonly used is false The default is in the bubbling phase )

a key :ele.addEventListener(type, handler) Remember to write Can solve on+ Of the type of event bug
Listener binding :

Listener unbinding :

Event object :

Stop the event from bubbling :
-- Purpose : If there are multiple boxes nested Click on the smallest box to jump The existence of bubbles may affect the opening and jumping of the current page The outermost page will be opened for jump analysis So this situation does not meet my needs Prevent default bubbling behavior
To prevent a bubble : Event object
- stopPropagation() It's a method ( Stop spreading ) Can only be used in higher versions
- e.cancelBubble = true Use in lower versions

Methods to prevent browser default behavior :preventDefault()
边栏推荐
猜你喜欢

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph

Docker modifies the user name and password of MySQL

TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush

Day39 prototype chain and page fireworks effect 2021.10.13

day36 js笔记 ECMA6语法 2021.10.09

动态库(共享库)的制作和使用

vsftpd服务的部署及优化

科研丨Web of Science检索技巧
![[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)](/img/e8/21d8d81a3d7b544687d6adc06ad4b1.png)
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)
随机推荐
什么是DAPP系统发展与解析理解
JS基础10
Setinterval, setTimeout and requestanimationframe
网页提示此站点不安全解决方案
毕业季,给初入社会的你一些建议
Day23 JS notes 2021.09.14
[sword finger offer] 49 Ugly number
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
String & heap & method area
JS foundation 2
科研丨Web of Science检索技巧
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
Wireshark数据抓包分析之FTP协议
2022中国信通院首届业务与应用安全发展论坛成功召开!
MySql5.7添加新用户
无法重新声明块范围变量
JS基础8
day39 原型链及页面烟花效果 2021.10.13
实体转JSON时,值为null的字段的丢失问题