当前位置:网站首页>DOM day_ 03 (7.11) event bubbling mechanism, event delegation, to-do items, block default events, mouse coordinates, page scrolling events, create DOM elements, DOM encapsulation operations
DOM day_ 03 (7.11) event bubbling mechanism, event delegation, to-do items, block default events, mouse coordinates, page scrolling events, create DOM elements, DOM encapsulation operations
2022-07-27 00:41:00 【Add 1 bed of bedding】
One 、 Event bubbling mechanism
The bubbling mechanism of events : When an event occurs on a child element , Will be passed to its parent element
Stop spreading : Dependent on event parameters stopPropagation Method
Event triggered party elements : The event target attribute
purpose : In event delegation mode , It can handle the events of dynamically added sub elements


Two 、 Event delegation
problem : Read original string After splicing , Get a new . Reset to ul Child elements
We have added click events before li, All replaced . So it can't be clicked
For dynamic addition / Changing sub elements : You can add a click event to its parent element
Event delegation : Let the parent element help the child element complete the operation related to the event

practice

3、 ... and 、 To do list


Four 、 Block default events
a label with href attribute , When clicked, it will automatically jump to the page
hope : by a Add click event to tag Instead of the default href Jump
By default : Trigger first onclick Trigger again href Jump

5、 ... and 、 Mouse coordinates


6、 ... and 、 Event listener
In teamwork :
Multi person collaborative development , If you use onclick Bind events by . Once two people give the same element onclick The binding event , Then there is a conflict , Cover .
demand : There will be no coverage , Can bind multiple events at the same time -- Event listener
addEventListener add add to event event listener Monitor
Two parameters : Event name -- No on, Trigger function
One time trigger function : removeEventListener

7、 ... and 、 Page scrolling Events
scroll: rolling . Browser page scrolling event
document.documentElement.scrollTop || document.body.scrollTop: How to get the rolling distance Because of the browser compatibility problem, it is best to use two solutions


8、 ... and 、 How attributes operate

7、 ... and 、 establish DOM Elements
Conventional web development methods :
use HTML Code build page -> Browser handle HTML It can be interpreted as DOM -> Show to browser
HTML Code is syntax sugar , The purpose is to facilitate programmers to develop
shortcoming : The browser needs to consume certain resources To convert Text ->DOM object
extreme : If you want to pursue extreme performance , Can be abandoned HTML Code , Direct use JS Way to create DOM Elements , That is to omit the steps of browser parsing , Artificially implement parsing DOM operation , Simply put, it's a programmer's job Replace the browser
This idea is in Of the three frameworks React Carry forward in the future -- Facebook

Loop creation DOM Elements
Document fragment : A virtual container , Can temporarily store DOM Elements Not displayed on the page

8、 ... and 、DOM Package operation
This package idea , Namely jQuery Thought , Using packaging technology , Put the original DOM simplified

边栏推荐
- [4.6 detailed explanation of Chinese remainder theorem]
- 【3. 基础搜索与图论初识】
- Apply with new, delete and malloc, free to free the heap space
- 3_ Jupiter notebook, numpy and mattlotlib
- [Qt]容器类、迭代器、foreach关键字
- 简单的素数程序 初学者 希望码龄高的大佬可以一下
- Drawing warehouse-2 (function image)
- "Syntaxerror: future feature annotations is not defined"
- Operator overloading
- Use of postman
猜你喜欢

2022-07-17:1, 2, 3... N-1, N, n+1, n+2... In this sequence, only one number has repetition (n). This sequence is unordered. Find the repeated number n. This sequence is ordered. Find the repeated numb

Use of postman

CSDN article syntax rules

Request attribute in crawler

9_ Logistic regression

Deployment of yolov5 on Jetson nano deepstream

2022_ SummerBlog_ 008

Signal and system learning zero input response

C语言 求素数、闰年以及最小公倍数最大公约数

Helicopter control system based on Simulink
随机推荐
Lt9611ux Mipi to HDMI 2.0 dual port with audio
【Codeforces Round #807 (Div 2.) A·B·C】
Based on the theoretical principle and simulation results of MATLAB spherical decoding, compare 2norm spherical decoding, infinite norm spherical decoding, ML detection
6_梯度下降法(Gradient Descent)
Signal and system learning zero input response
DOM day_03(7.11) 事件冒泡机制、事件委托、待办事项、阻止默认事件、鼠标坐标、页面滚动事件、创建DOM元素、DOM封装操作
Collection of 3D LUT related articles
AutoCAD的卸载后重新安装,删除注册表的详细过程
Complete review of parsing web pages
CDs simulation of minimum dominating set based on MATLAB
Knowledge distillation -- pytorch implementation
10_评价分类结果(Evaluate classification)
[Qt]元对象系统
蓝桥杯 1004 [递归]母牛的故事
"Could not load host key" error when xshell connects to the server
In JS, the common writing methods and calling methods of functions - conventional writing, anonymous function writing, taking the method as an object, and adding methods to the object in the construct
Friend友元函数以及单例模式
[PCB open source sharing] stc8a8k64d4 development board
C语言 求素数、闰年以及最小公倍数最大公约数
公司给了IP地址如何使用(详细版)