当前位置:网站首页>三个点语法和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(); 停止观察
边栏推荐
- 实现web实时消息推送的7种方案
- Basemap and Seaborn
- [Qualcomm][Network] 网络拨号失败和netmgrd服务分析
- OC- about alloc and dealloc (haven't started writing yet)
- 零代码开发入门:快速上手DIY函数公式的5个步骤
- Security Thought Project Summary
- 【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
- wsl操作
- Redis Desktop Manager 2022.4.2 released
- 【AGC】增长服务2-应用内消息示例
猜你喜欢

Domino Server SSL Certificate Installation Guide

typescript入门之helloworld

图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images

AB测试 总结归纳

Telerik2022 R2,有效的自动化测试

ESP32CAM 1838接收红外遥控器信号

spark udf accepts and handles null values.

If someone asks you about distributed transactions again, throw this to him

Multithreading--the usage of threads and thread pools

Re19: Read the paper Paragraph-level Rationale Extraction through Regularization: A case study on European Court
随机推荐
TestNg整合Retry代码
salesforce使用方法(salesforce authenticator下载)
Easy gene: human tRNA gene loci showed age-related high DNA methylation | research articles
In 2022, the top will be accepted cca shut the list
【AGC】增长服务2-应用内消息示例
神经网络学习笔记3——LSTM长短期记忆网络
[HarmonyOS] [ARK UI] How to double-click the return key to exit in HarmonyOS ets language
分页 paging
In the robot industry professionals, Mr Robot industry current situation?
WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql
Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
MySQL之数据库维护
MFCC to audio, the effect should not be too funny >V
Unity 锁定相机第二弹
【HMS core】【FAQ】HMS Toolkit典型问题合集1
@RequestBody 和 @ResponseBody 详解
STM32CubeMX configuration to generate FreeRTOS project
jmeter接口压力测试(一)
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images