当前位置:网站首页>JS中对事件代理的理解及其应用场景
JS中对事件代理的理解及其应用场景
2022-08-02 00:14:00 【weixin_46051260】
事件代理:把一个元素响应事件的函数委托到另一个元素身上,也叫事件委托
事件流:捕获截断–>目标阶段–>冒泡阶段(事件委托)
如下:只要操作一次dom,提高了程序的性能
<ul id="list">
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
let lis=document.querySelectorAll('li')
/* for(let i=0;i<lis.length;i++){ lis[i].οnclick=function(e){ console.log(e.target.innerHTML); } } */
let list=document.querySelector('#list')
list.onclick=function(e){
console.log(e.target.innerHTML);
}
边栏推荐
- Routing strategy
- 已知中序遍历数组和先序遍历数组,返回后序遗历数组
- 什么是低代码(Low-Code)?低代码适用于哪些场景?
- PHP to read data from TXT file
- Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can
- ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
- 微软电脑管家V2.1公测版正式发布
- BGP first experiment
- Redis的集群模式
- Play NFT summer: this collection of tools is worth collecting
猜你喜欢

协作乐高 All In One:DAO工具大全

146. LRU cache

How to design a circular queue?Come and learn~

Short video SEO optimization tutorial Self-media SEO optimization skills and methods

Task execution control in Ansible

Quick solution for infix to suffix and prefix expressions

BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合

当奈飞的NFT忘记了Web2的业务安全

go笔记——map

nodeJs--mime模块
随机推荐
Collection of NFT tools
JSP out.println()方法具有什么功能呢?
Short video SEO search operation customer acquisition system function introduction
What does the errorPage attribute of the JSP page directive do?
短视频SEO搜索运营获客系统功能介绍
unity2D横版游戏教程5-UI
扑克牌问题
Unknown CMake command “add_action_files“
nodeJs--mime模块
A simple file transfer tools
众筹DAO“枯萎”的缩影:曾拍下《沙丘》未出版手稿的Spice DAO解散
【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
MLX90640 红外热成像仪测温传感器模块开发笔记(十) 成果展示-红眼睛相机
An overview of the most useful DeFi tools
Pytorch seq2seq 模型架构实现英译法任务
Cyber-Physical System State Estimation and Sensor Attack Detection
String splitting function strtok exercise
2022/08/01 学习笔记 (day21) 泛型和枚举
nodeJs--各种路径
Identify memory functions memset, memcmp, memmove, and memcpy