当前位置:网站首页>简单理解事件
简单理解事件
2022-06-11 17:26:00 【大船叔叔】
什么是事件
对用户操作做出反应
事件的作用
1 :实现用户行为与浏览器页面的交互
2 :监听机器.进度,动画等
事件解决了的问题
让界面活起来
分析流程
- 1.用户对哪一个元素,做了什么事
给哪个元素,绑定了什么事件
- 2.做了这件事后浏览器展示什么效果
在事件处理函数中编写哪些代码
事件里面的具体内容
事件处理函数
- 1.执行慢的函数
- 在全局后面去执行的代码
- 2.当触发事件的时候执行函数
事件分类
- 内置事件
事件参考清单
如何知道应该用哪一个事件?
1.分析行为 2.根据行为查找事件
- 自定义事件
事件对象
- 作用 : 记录触发事件的详细信息
- 1.触发事件的元素
- 2.事件类型
- 3.触发事件位置
- 4.触发事件时间
- 5.键盘中的哪个案件
- …
- 获取 : 事件处理函数形参
- 用途 :
- 1.查找出触发事件元素
- 2.获取触发事件元素名,区分 谁触发的事件(事件委托)
事件委托
事件委托:
1.利用事件流的特点来绑定事件的一种方式
2.给绑定事件的目标元素的父元素绑定事件 以此来减少目标元素的事件绑定次数 从而优化程序事件委托绑定方式
// 普通动态绑定事件
// var ulNode = document.createElement('ul');
// document.body.appendChild(ulNode);
// for (let index = 0; index < 10; index++) {
// var liNode = document.createElement('li');
// liNode.innerHTML = `${index + 1}`;
// liNode.onclick = function () {
// this.style.backgroundColor = 'green';
// }
// ulNode.appendChild(liNode)
// }
// 事件委托动态绑定事件
var ulNode = document.createElement('ul');
document.body.appendChild(ulNode);
ulNode.onclick = function (event) {
if (event.target.nodeName == 'LI') {
event.target.style.backgroundColor = 'green'
} else {
console.log('点的不是li');
}
}
for (let index = 0; index < 10; index++) {
var liNode = document.createElement('li');
liNode.innerHTML = `${
index + 1}`;
ulNode.appendChild(liNode)
}
边栏推荐
- adb 命令学习笔记
- Vscode configures eslint to automatically format an error "auto fix is enabled by default. use the single string form“
- 如何成为一个乐观派组织?
- Mathematical foundations of information security Chapter 3 - finite fields (I)
- Service learning notes 02- actual combat startservice and bindservice
- tidb-ddl的速度的调整
- require和ES6 import的区别
- 信息安全数学基础 Chapter 4——二次剩余与方根
- TestPattern error
- Authing 双周动态:应用市场上线(5 .10 —5 .22 )
猜你喜欢

Summary of clustering methods

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod

Is the second-class cost engineer worth the exam? What is the development prospect?

括号生成---2022/02/25
![[online problem] timeout waiting for connection from pool](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool

有效的括号---2022/02/23

Bentley 使用 Authing 快速实现应用系统与身份的集成

How does Sister Feng change to ice?

【Mysql】redo log,undo log 和binlog详解(四)

Automated testing selenium
随机推荐
Service learning notes 02- actual combat startservice and bindservice
tidb-写热点的测试及分析
【线上问题】Timeout waiting for connection from pool 问题排查
Set object mapping + scene 6-face mapping + create space in threejs
Use of forcescan in SQL server and precautions
Is it safe for Xiaobai to open an account directly on the flush?
Biden ordered to enforce the zero trust structure
ADB command learning notes
【深度学习基础】神经网络的学习(3)
导出数据提示--secure-file-priv选项问题的解决方法
6-3 批量求和(*)
6-3 读文章(*)
C language: use H and C. summary of problems encountered in documents
Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool
聚类方法汇总
Cs0006 C failed to find metadata file "c:\users\... Problem
TiDB-unsafe recover(tikv宕机数大于等于一半副本数)
vscode保存代码时自动eslint格式化
7-2 h0107. Pig-Latin
Centos7 server configuration (IV) -- installing redis