当前位置:网站首页>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);
}
边栏推荐
- JSP request对象功能详解说明
- 测试点等同于测试用例吗
- 【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
- 众筹DAO“枯萎”的缩影:曾拍下《沙丘》未出版手稿的Spice DAO解散
- 基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
- Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
- Are test points the same as test cases?
- MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
- ROS dynamic parameters
- Unknown CMake command "add_action_files"
猜你喜欢

08-SDRAM: Summary

Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)

Pytorch seq2seq 模型架构实现英译法任务

C language character and string function summary (2)

Routing strategy

An overview of the most useful DeFi tools

C语言实现扫雷游戏

146. LRU 缓存

These 4 computer notepad software, you have to try

回顾历史5次经济衰退时期:这一次可能会有何不同?
随机推荐
Difference between JSP out.print() and out.write() methods
【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
Using the "stack" fast computing -- reverse polish expression
Routing strategy
go笔记——锁
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
460. LFU cache
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
Short video SEO search operation customer acquisition system function introduction
什么是低代码(Low-Code)?低代码适用于哪些场景?
Are test points the same as test cases?
Redis 相关问题
JSP内置对象out对象的功能简介说明
Redis的集群模式
JSP out.println()方法具有什么功能呢?
JSP如何使用page指令让JSP文件支持中文编码呢?
Kotlin协程:创建、启动、挂起、恢复
Web开发
go语言标准库fmt包怎么使用
回顾历史5次经济衰退时期:这一次可能会有何不同?