当前位置:网站首页>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()
边栏推荐
- Analyze whether there is duplicate data in the list and repeat it several times
- Mysql安装配置以及解决重装Mysql时忘记root password问题
- [sword finger offer] 49 Ugly number
- Apache2配置对目录拒绝访问,但是可以访问里面文件的设置
- Web page tips this site is unsafe solution
- [no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
- QML control type: tabbar
- Excel导入导出便捷工具类
- 【剑指Offer】49. 丑数
- Scientific research - web of science retrieval skills
猜你喜欢
随机推荐
day24 js笔记 2021.09.15
Setinterval, setTimeout and requestanimationframe
关于Pytorch中双向LSTM的输出表示问题
字符串 & 堆 & 方法区
论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph
TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
windows 10下载安装mysql5.7
Cannot redeclare block range variables
GDB简介
MySQL installation configuration and solving the problem of forgetting root password when reinstalling MySQL
Oracle 日期格式化异常:无效数字
【剑指Offer】49. 丑数
JS基础8
day33 js笔记 事件(下)2021.09.28
JS基础3
SQL必需掌握的100个重要知识点:检索数据
day23 js笔记 2021.09.14
无法重新声明块范围变量
Class pattern and syntax in JS 2021.11.10
setInterval、setTimeout和requestAnimationFrame