当前位置:网站首页>三个点语法和DOM观察者
三个点语法和DOM观察者
2022-08-08 11:53:00 【勇敢*牛牛】
三个点语法和DOM观察者
var arr=[1,2,3,4];
var arr1=[...arr];
console.log(arr1)// [1, 2, 3, 4]
var arr=[1,2,3,4];
var arr1=[0,...arr,5,6];
console.log(arr1)//[0, 1, 2, 3, 4, 5, 6]
…arr 是剩余的参数
function fn(a,b,...arg){
console.log(a,b,arg)
}
fn(1,2,3,4,5,6);1 2 (4) [3, 4, 5, 6]
扩展对象键值对
var o={
a:1,b:2,c:3};
var o1={
e:5,...o};
console.log(o1)//{e: 5, a: 1, b: 2, c: 3}
复制一个对象
Object.assign({
},{
a:1,b:2});
DOM观察者
new MutationObserver(回调函数)
回调函数 有两个参数,一个mutationList观察变化的列表 observer 观察者
var div=document.querySelector("div");
var observer= new MutationObserver(function(mutationList,observer){
console.log(mutationList)
for(var i=0;i<mutationList.length;i++){
console.log(mutationList[i].oldValue)
}
// attributeName: "cd" 修改的标签属性
// type: "attributes" 变化的类型 attributes 标签属性变化 childList 子元素列表变化
// addedNodes: 增加的元素列表
// removedNodes 删除的元素列表
// target: span 目标元素
// oldValue: null 原来的值
})
根据上面创建的观察者实现观察,观察div的变化
observer.observe(div,{
attributes:true,//标签属性
childList:true,//子元素列表
subtree:true//子树
})
div.setAttribute("ab","3");
div.firstElementChild.setAttribute("cd","3")
div.firstElementChild.textContent="abc"
var span=document.createElement("span");
div.firstElementChild.appendChild(span);
span.remove();
div.lastElementChild.value="10"
div.lastElementChild.setAttribute("value","10")
observer.disconnect(); 停止观察
边栏推荐
- 300万招标!青岛市医疗保障局主机数据库中间件运行维护服务项目
- 手绘地图制作的关键点之“图层覆盖”
- 三、集合与字典
- [Horizon Rising Sun X3 Trial Experience] WIFI connection, SSH login, TogetherROS installation (section 2)
- DDoS攻击为什么是无解的
- ReentrantLock原理,ReentrantLock和synchronized区别
- 字节也开始缩招了...
- LeetCode_66_加一
- 关于win下面Celery服务报 Process 'Worker' exited with 'exitcode 1' [duplicate]
- 模式识别 学习笔记:第七章 特征选择
猜你喜欢
一起学习集合框架之 TreeSet
内网渗透学习(五)域横向移动——PTH&PTK&PTT
微服务负载均衡器LoadBalancer实战
MySQL----索引
RT-Thread记录(三、RT-Thread 线程操作函数及线程管理与FreeRTOS的比较)
【AI系统前沿动态第45期】Hinton:深度学习的下一个大事件;一块GPU训练TB级推荐模型不是梦;AI-GPU显存优化发展史
论文阅读《Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras》
day01 - Introduction to Web API - Introduction to DOM - Getting Elements - Event Basics - Manipulating Elements - Exclusive Operations - Custom Attribute Operations - Node Operations - Cases: Dynamica
五、树结构
研究:有毒的PFAS化学品使全球各地的雨水无法安全饮用
随机推荐
高可用的并行MySQL数据同步及分布式
ets声明式ui开发,怎么获取当前系统时间
leetcode 1584. 连接所有点的最小费用
JVM的GC讲解及调优
【AI系统前沿动态第45期】Hinton:深度学习的下一个大事件;一块GPU训练TB级推荐模型不是梦;AI-GPU显存优化发展史
Redis 定长队列的探索和实践
Classificition Loss in target detection
【访谈】Eotalk Vol.01:Eoapi,我们希望以开源的方式构建 API 生态系统
贵州酒店集团特产券解析
E121: Unable to open and write file solution when vim /etc/profile is written
shell之常用小工具
字节也开始缩招了...
leetcode:761. 特殊的二进制序列【递归 + 转换有效括号】
Mobile adaptation method of vw/vh - vw/vh instance - analog B stand mobile home page - get style tutorial video
STM32的内存管理相关(内存架构,内存管理,map文件分析)
(原创)[C#] GDI+ 之鼠标交互:原理、示例、一步步深入、性能优化
win10安装Solidworks2016安装出错:solidworks\sldfuncfeat.dll“ 已返回 0x3,如何解决.
LeetCode_1004_最大连续1的个数Ⅲ
无心剑2022年七绝100首
day02 -DOM—高级事件(注册事件、事件监听、删除事件、DOM事件流、事件对象、阻止默认行为、阻止事件冒泡、事件委托)—常用鼠标事件—常用的键盘事件