当前位置:网站首页>Simple understanding of events
Simple understanding of events
2022-06-11 17:43:00 【Uncle ship】
What is an event
React to user actions
The role of the event
1 : Realize the interaction between user behavior and browser page
2 : Monitor machine . speed of progress , Animation, etc.
The event solved the problem of
Make the interface live
Analysis process
- 1. Which element does the user want , What has been done
To which element , What events are bound
- 2. After doing this, what effect does the browser show
What code to write in the event handler
The details of the event
Event handler
- 1. Execute slow functions
- Code to be executed after the overall situation
- 2. Execute the function when the event is triggered
Event classification
- Built in events
Event reference list
How to know which event to use ?
1. Analyze behavior 2. Find events based on behavior
- Custom events
Event object
- effect : Record the details of the trigger event
- 1. The element that triggered the event
- 2. Event type
- 3. Trigger event location
- 4. Trigger event time
- 5. Which case in the keyboard
- …
- obtain : Event handler parameters
- purpose :
- 1. Find the trigger event element
- 2. Get the trigger event element name , distinguish Who triggered the event ( Event delegation )
Event delegation
Event delegation :
1. A way to bind events by using the characteristics of event flow
2. Bind an event to the parent element of the target element of the bound event This reduces the number of event bindings for the target element So as to optimize the programEvent delegate binding method
// Normal dynamic binding events
// var ulNode = document.createElement('ul');
// document.body.appendChild(ulNode);
// for (let index = 0; index < 10; index++) {
// var liNode = document.createElement('li');
// liNode.innerHTML = `${index + 1}`;
// liNode.onclick = function () {
// this.style.backgroundColor = 'green';
// }
// ulNode.appendChild(liNode)
// }
// Event delegate dynamically binds events
var ulNode = document.createElement('ul');
document.body.appendChild(ulNode);
ulNode.onclick = function (event) {
if (event.target.nodeName == 'LI') {
event.target.style.backgroundColor = 'green'
} else {
console.log(' No li');
}
}
for (let index = 0; index < 10; index++) {
var liNode = document.createElement('li');
liNode.innerHTML = `${
index + 1}`;
ulNode.appendChild(liNode)
}
边栏推荐
猜你喜欢

ffmpeg硬件编解码Nvidia GPU
![[foundation of deep learning] learning of neural network (3)](/img/a5/1b80ba85faf8fa636b784c76d4df2f.png)
[foundation of deep learning] learning of neural network (3)

Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool

【线上问题】Timeout waiting for connection from pool 问题排查

Use exe4j to convert The jar file is packaged as Exe file

Merge two ordered linked lists ---2022/02/24

Ffmpeg hard codec inter QSV

Service学习笔记01-启动方式与生命周期

ffmpeg硬编解码 Inter QSV

Hands on deep learning - multiple input and output channels in the convolution layer
随机推荐
Service learning notes 02- actual combat startservice and bindservice
6-8 reading and writing of structured files 1
Hash table, inheritance
【深度学习基础】神经网络的学习(3)
av_read_frame返回值为-5 Input/output error
Merge two ordered linked lists ---2022/02/24
Bracket generation ---2022/02/25
ffmpeg奇偶场帧Interlace progressive命令和代码处理
6-3 reading articles (*)
括号生成---2022/02/25
Leetcode force deduction question
tidb-ddl的速度的调整
Valid parentheses ---2022/02/23
Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
04_ Feature engineering feature selection
Tidb unsafe recover (tikv downtime is greater than or equal to half the number of replicas)
Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“
Tidb CDC log tables are not eligible to replicate
Go path: goroot & gopath
6-3 reading articles (*)