当前位置:网站首页>JS event introduction
JS event introduction
2022-07-29 01:33:00 【godton】
Flow of events
Click on an element in a page , This element is not the only one that triggers , It also includes all the parent content outside this element ; Use the description of the red book : Draw several concentric circles on a piece of paper , Put your finger in the center of the circle , It is also placed in the center of all circles . IE Browser and Netscape browser use two methods to deal with this contradiction .
1. Event Bubbling
IE The browser adopts the bubbling method , Bubbling is from the underlying element To the highest element Document First floor One layer bubbles upward :div -> body -> html -> document
2. Event capture
Netscape browser is just the opposite , From the top , The element finally captures the event document -> html -> body -> div
And in the DOM2 period , Three stages of the event are defined , Event capture 、 Reach the target 、 Event Bubbling .
Event handler
Event handling is divided into DOM0 and DOM2 Event handling ,DOM0 In design pattern, it is observer pattern , Is triggered in the bubbling stage
DOM0 Event handler
let btn = document.getElementById('mybtn')
btn.onClick = function() {
console.log('clicked')
}
but DOM1 The event will be overwritten , Only one corresponding function can be processed .
DOM2 Event handler
DOM2 The event processing of can control whether it is triggered in the bubbling stage or the capture stage , Is the publish subscribe mode .addEventListener( 'Event', Function, Boolean)
Event Is the name of the triggered event ,Function Is the corresponding processing function ,Boolean Of flase Is the default value , Indicates that in the bubbling stage ;true For the capture phase .
let btn = document.getElementById('mybtn')
btn.addEventLisenter('click' _ => {
console.log('clicked'), true)
DOM2 The advantage of is that you can add multiple processing functions , And will not be covered
let btn = document.getElementById('mybtn')
btn.addEventLisenter('click' _ => {
console.log('clicked'), true)
btn.addEventLisenter('click' _ => {
console.log('HelloWorld'), false)
Event object
All events have their own event object , This object will be passed in when calling the function
let btn = document.getElementById('mybtn')
btn.onClick = function(e) {
console.log(e) //PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …}
}
let btn = document.getElementById('mybtn')
btn.addEventLisenter('click' e => {
console.log(e), true)
//PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …}
Objects contain many properties , Include target,type, view Various operations on the event are based on the event object .
Event type
There are many types of events , There are different events under each event type , Most of the event types are as follows :
- User interface events
- "Event"
- Wheel event
- Input event
- Keyboard events
- Composite event
- html5 event
- ( Mobile devices )
- Touch screen events
- Device events
- Gesture events
边栏推荐
- Understand various paths
- Test / development programmers rely on technology to survive the midlife crisis? Improve your own value
- Flink Postgres CDC
- Cookies and sessions
- Expression evaluation
- HCIA配置实例(eNSP)
- 括号匹配的检验
- App access kakaotalk three party login
- numpy.where() 用法和np.argsort()的用法
- Linux redis source code installation
猜你喜欢

Error reporting: SQL syntax error in flask. Fields in SQL statements need quotation marks when formatting

mysql 创建索引的三种方式

Docker compose install MySQL
![A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]](/img/aa/a5e7b4516aa395f8d4d0e2eee7d3c7.png)
A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]

Oozie工作调度

Redis is installed on Linux

Cross modal alignment 20220728

时间复杂度、空间复杂度的学习总结

Bracket matching test

2022年最火的十大测试工具,你掌握了几个
随机推荐
(update 20211130) about the download and installation of Jupiter notebook and its own configuration and theme
瑞吉外卖项目实战Day01
Expression evaluation
过去10年的10起重大网络安全事件
Moonbeam上的多链用例解析——Derek在Polkadot Decoded 2022的演讲文字回顾
18 diagrams, intuitive understanding of neural networks, manifolds and topologies
Comprehensive upgrade, all you can imagine is here -- JD API interface
Letax record \documentclass{}, authoryear attribute is used
Test / development programmers rely on technology to survive the midlife crisis? Improve your own value
[leetcode sliding window problem]
云原生应用综合练习上
log4j动态加载配置文件
Embedded sharing collection 23
vm options、program arguments、environment property
C language 300 lines of code to achieve mine sweeping (deployable + markable + changeable difficulty level)
Synchronized关键字详解
20220728 sorting strings that are not pure numbers
【ManageEngine】助力哈尔滨工程大学实现网络流量一体化监控管理
【HCIP】重发布及路由策略的实验
Google play APK uploads other international app stores