当前位置:网站首页>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);
}
边栏推荐
- [21-Day Learning Challenge] A small summary of sequential search and binary search
- 路由策略
- How does JSP use the page command to make the JSP file support Chinese encoding?
- 工业信息物理系统攻击检测增强模型
- After an incomplete recovery, the control file has been created or restored, the database must be opened with RESETLOGS, interpreting RESETLOGS.
- Detailed explanation of JSP request object function
- 08-SDRAM: Summary
- 短视频SEO优化教程 自媒体SEO优化技巧方法
- 短视频SEO搜索运营获客系统功能介绍
- bgp 聚合 反射器 联邦实验
猜你喜欢
随机推荐
微软电脑管家V2.1公测版正式发布
JSP page指令errorPage属性起什么作用呢?
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
链上治理为何如此重要,波卡Gov 2.0又会如何引领链上治理的发展?
面试:简单介绍你参与的一个项目
路由策略
Looking back at 5 recessionary times in history: How might this time be different?
测试用例:四步测试设计法
Disk and file system management
DFS详解
回顾历史5次经济衰退时期:这一次可能会有何不同?
[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
What is the function of the JSP Taglib directive?
JSP how to obtain the path information in the request object?
【HCIP】BGP小型实验(联邦,优化)
鲲鹏编译调试插件实战
辨析内存函数memset、memcmp、memmove以及memcpy
Trie详解
632. Minimum interval
How to use the go language standard library fmt package








