当前位置:网站首页>三个点语法和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(); 停止观察
边栏推荐
- xshell使用技巧(赚分享平台怎么样)
- Re20:读论文的先例:普通法的信息理论分析
- MySQL之数据库维护
- OC- about alloc and dealloc (haven't started writing yet)
- 拖放事件,dataTransfer,getBoundingClientRect
- 现在报PMP还来得及参加9月的考试吗?分享敏捷全真模拟题
- STM32CubeMX configuration to generate FreeRTOS project
- 208. 实现 Trie (前缀树)
- MFCC转音频,效果不要太逗>V<!
- 【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1
猜你喜欢

In the robot industry professionals, Mr Robot industry current situation?

PyQt5 - draw text on window

Multithreading--the usage of threads and thread pools

Neural Network Study Notes 3 - LSTM Long Short-Term Memory Network

Materialist Dialectics - Conditionalism

Neural Network Study Notes 4 - Autoencoder (including sparse, stacked) (updated)

Domino Server SSL Certificate Installation Guide

现在报PMP还来得及参加9月的考试吗?分享敏捷全真模拟题
![[Deep Learning] (Problem Record) <What do I get by calculating the gradient of a variable> - Linear Regression - Small Batch Stochastic Gradient Descent](/img/28/834aac16859fd26ab69de30f5fed55.png)
[Deep Learning] (Problem Record)
- Linear Regression - Small Batch Stochastic Gradient Descent ![[AGC] Growth Service 2 - In-App Message Example](/img/fa/9190e45c1532aec908a6c68706629a.png)
[AGC] Growth Service 2 - In-App Message Example
随机推荐
类和对象—6个默认成员函数
VLAN实验
MFCC转音频,效果不要太逗>V<!
Security Thought Project Summary
Oracle中SQL语言和分页rownum分析
Soft test system architects introductory tutorial | system operation and software maintenance
OC-关于alloc和dealloc(还没开始写)
Easy gene: human tRNA gene loci showed age-related high DNA methylation | research articles
还在用Swagger?我推荐这款零代码侵入的接口管理神器
Domino Server SSL Certificate Installation Guide
Re15: Read the paper LEVEN: A Large-Scale Chinese Legal Event Detection Dataset
typescript入门之helloworld
第2章 常用安全工具
OC-ARC (Automatic Reference Counting) automatic reference counting
第1章 Kali与靶机系统
WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql
PyQt5 - draw sine curve with pixels
梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发
OC-ARC(Automatic Reference Counting)自动引用计数
简述controller,service,repository注解的用法(谈谈application.properties的作用)