当前位置:网站首页>JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
2022-07-28 19:54:00 【HandsomeDanielWu】


this




<body>
<button id="btn"> Press me to add a new li list </button>
<ul id="list">
<li> Default label </li>
<li> Default label </li>
<li> Default label </li>
</ul>
<script>
var oBtn = document.getElementById('btn');
var oList = document.getElementById('list');
var lis = oList.getElementsByTagName('li');
// Turn red
var redFunc = function(){
this.style.color = 'red';
};
// Give default li Add click event
for (var i = 0; i < lis.length; i++){
lis[i].onclick = redFunc;
};
// Add a new label
oBtn.onclick = function () {
var oli = document.createElement('li');
oli.innerHTML = ' Add new options ';
oList.appendChild(oli);
// New tags , You must add listening events manually
oli.onclick = redFunc;
};
</script>
</body>

Solve the above problems : Event delegation


target currentTarget












onmouseenter onmouseover



<li> Is a block level element , Natural width max



边栏推荐
- With the help of panel industry innovation, will FPGA become the best choice for TCON?
- English Translation Spanish - batch English Translation Spanish tools free of charge
- 11、 学习MySQL UNION 操作符
- STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
- 串口接收应用——环形缓冲buffer
- 业务可视化-让你的流程图“Run“起来(4.实际业务场景测试)
- Huawei shares in Nanjing core vision, laying out the solid-state laser radar chip field
- 冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
- 软考中级(系统集成项目管理工程师)高频考点
- Leetcode Day5 delete duplicate email
猜你喜欢

基于QTGUI图像界面的空战游戏设计

Thoroughly understand bit operations - shift left, shift right

利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)

How many types of rain do you know?

Netcoreapi operation excel table

数字图像理论知识(一)(个人浅析)

Codeignier framework implements restful API interface programming

11. Learn MySQL union operator

Source insight project import and use tutorial

Idea properties file display \u solution of not displaying Chinese
随机推荐
华为入股南京芯视界,布局固态激光雷达芯片领域
Getting started with saltstack
NetCoreAPI操作Excel表格
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
Convertible bond concept table x notation gives you a convenient and fast experience!
Use Hal Library of STM32 to drive 1.54 inch TFT screen (240*240 st7789v)
Redis notes
adb remount of the / superblock failed: Permission denied
Integration and implementation of login click graphic verification code in personal blog system
leetcode day5 删除重复的电子邮箱
Article translation software - batch free translation software supports major translation interfaces
Implementation of markdown editor in editor.md
助力面板行业创新,FPGA将成屏厂TCON最佳选择?
Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters
投资35.45亿元!格力集团参与小米产业基金
String中常用的API
Information management system and games based on C language
Cloud computing notes part.1 - system management
Preliminary learning function (3rd blog)
Leetcode Day1 score ranking