当前位置:网站首页>三个点语法和DOM观察者
三个点语法和DOM观察者
2022-07-30 10:34: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(); 停止观察
边栏推荐
- MySQL installation tutorial [installation version]
- mysql与redis 区别
- MySQL |子查询
- 360 released a future-oriented EDR to protect the security of government and enterprise user terminals in an all-round way
- Drag and drop events, dataTransfer, getBoundingClientRect
- log4j Logger简介说明
- Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
- 从数据流中快速查找中位数
- Flink_CDC construction and simple use
- vscode中写markdown格式笔记的配置过程和相关语法
猜你喜欢

flowable workflow all business concepts

Neural Ordinary Differential Equations

JCL learning

易基因:人类tRNA基因位点表现出与衰老相关的DNA高甲基化|研究文章

Pytorch中 nn.Transformer的使用详解与Transformer的黑盒讲解

加密和安全

Is it too late to apply for PMP now to take the September exam?Share agile full-true mock questions

从数据流中快速查找中位数

jmeter接口压力测试-(二)

SST-Calib:结合语义和VO进行时空同步校准的lidar-visual外参标定方法(ITSC 2022)
随机推荐
Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
Security思想项目总结
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
Re19: Read the paper Paragraph-level Rationale Extraction through Regularization: A case study on European Court
梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发
JCL learning
Js array operating mobile for encapsulation
Quick Start Tutorial for flyway
Telerik2022 R2,有效的自动化测试
AB测试 总结归纳
WebAPI 复习
零代码开发入门:快速上手DIY函数公式的5个步骤
log4j Logger简介说明
Do you really understand the 5 basic data structures of Redis?
Is it too late to apply for PMP now to take the September exam?Share agile full-true mock questions
FPGA刷题——计数器(简易秒表、可置位计数器、加减计数器)
OC - Manual Reference Counting Memory Management
TestNg整合Retry代码
In 2022, the top will be accepted cca shut the list
OC-手动引用计数内存管理