当前位置:网站首页>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);
}
边栏推荐
- What is the function of the JSP Taglib directive?
- JSP如何使用request获取当前访问者的真实IP呢?
- 06-SDRAM : SDRAM control module
- JSP 如何获取request对象中的路径信息呢?
- How to use the go language standard library fmt package
- 协作乐高 All In One:DAO工具大全
- MLX90640 红外热成像仪测温模块开发笔记(完整版)
- Automatic conversion of Oracle-style implicit joins to ANSI JOINs using jOOQ
- Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
- swing的Jlist列表滚动条以及增加元素的问题
猜你喜欢
bgp aggregation reflector federation experiment
Microsoft PC Manager V2.1 beta version officially released
已知中序遍历数组和先序遍历数组,返回后序遗历数组
Arduino Basic Syntax
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
[21-Day Learning Challenge] A small summary of sequential search and binary search
路由策略
Play NFT summer: this collection of tools is worth collecting
磁盘与文件系统管理
[HCIP] BGP Small Experiment (Federation, Optimization)
随机推荐
JSP out.print()和out.write()方法的不同之处
Mean Consistency Tracking of Time-Varying Reference Inputs for Multi-Agent Systems with Communication Delays
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
How does JSP use request to get the real IP of the current visitor?
JSP out. The write () method has what function?
els block deformation
Detailed explanation of JSP request object function
Difference between JSP out.print() and out.write() methods
BGP 第一次实验
字符串分割函数strtok练习
攻防世界-web-Training-WWW-Robots
An interesting project--Folder comparison tool (1)
Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
玩转NFT夏季:这份工具宝典值得收藏
go笔记记录——channel
go笔记——map
go笔记——锁
辨析内存函数memset、memcmp、memmove以及memcpy
[Headline] Written test questions - minimum stack
What is the function of the JSP Taglib directive?