当前位置:网站首页>事件委托的使用与说明》
事件委托的使用与说明》
2022-06-30 09:35:00 【zimingyo】
事件委托
总结
- 优点:给父级元素加事件(可以提高性能)
- 原理:事件委托其实是利用事件冒泡的特点,给父级元素添加事件,子元素可以触发
- 实现:事件对象.target可以获得正真触发事件元素
<body>
<ui>
<li>第一个</li>
<li>第二个</li>
<li>第三个</li>
</ui>
<script> let ul=document.queryselect('ul') ul.addEventListener('click',function(e){
console.log(e)//获取Ul下的所有事件对象 console.log(e.target)//获得当前点击得li元素 console.log(e.target.style.color='red')//点击当前的li,使li的颜色变为红色 }) </script>
</body>
边栏推荐
- 无人机项目跟踪记录八十三---pcb图完成
- Configuring MySQL for error reporting
- MySQL优化
- Torch learning summary
- Principle and implementation of small program hand-held bullet screen (uni APP)
- Framework program of browser self-service terminal based on IE kernel
- 单片机 MCU 固件打包脚本软件
- Mysql database learning 1
- Pytorch graduate warm LR installation
- 3. integrate eslint and prettier
猜你喜欢
随机推荐
仿照微信Oauth2.0接入方案
1. Basic configuration
2021-11-15
Application exploration and practice of super convergence in the production environment of insurance industry
Bloom filter
Design of mfc+mysql document data management system based on VS2010
9.缓存优化
JWT expiration processing - single token scheme
UltraEdit delete empty line method
八大排序(一)
Theme Studio(主题工作室)
Slf4j: failed to load class "org.slf4j.impl.staticloggerbinder"
Practice of super integration and transformation of core production business of public funds
Pass anonymous function to simplification principle
qmlplugindump executable not found. It is required to generate the qmltypes file for VTK Qml
Follow the wechat oauth2.0 access scheme
[new book recommendation] mongodb performance tuning
Flume learning II - Cases
Cloud native database
JVM tuning tool introduction and constant pool explanation









