当前位置:网站首页>三个点语法和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(); 停止观察
边栏推荐
- [Deep Learning] (Problem Record)
- Linear Regression - Small Batch Stochastic Gradient Descent - WEB3之路(一)-- solidity学习笔记
- FPGA刷题——计数器(简易秒表、可置位计数器、加减计数器)
- Online target drone prompt.ml
- 零代码开发入门:快速上手DIY函数公式的5个步骤
- Telerik2022 R2,有效的自动化测试
- XYplorer 23多语言,最好的管理软件之一
- nacos实战项目中的配置
- 鸿湖万联扬帆富设备开发板正式合入OpenHarmony主干
- Matplotlib--plot markers
猜你喜欢

零代码开发入门:快速上手DIY函数公式的5个步骤

Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development

系统设计精选 | 基于FPGA的CAN总线控制器的设计(附代码)

hcip06 ospf special area comprehensive experiment

Re21: Read the paper MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real

第1章 Kali与靶机系统

Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory

Nacos configuration in the project of battle
![MySQL installation tutorial [installation version]](/img/e9/9c7b0e3aac22206d126de428c1a4bd.png)
MySQL installation tutorial [installation version]

Neural Network Study Notes 4 - Autoencoder (including sparse, stacked) (updated)
随机推荐
flowable workflow all business concepts
[HarmonyOS] [ARK UI] How to double-click the return key to exit in HarmonyOS ets language
【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1
【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?
[Qualcomm][Network] 网络拨号失败和netmgrd服务分析
Multithreading--the usage of threads and thread pools
【Flume】batchSize和transactionCapacity区别
VLAN相关知识点
Some commands of kubernetes
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
第1章 Kali与靶机系统
电压跟随器不要随便加
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
MFCC转音频,效果不要太逗>V<!
async.js入门
OC-关于alloc和dealloc(还没开始写)
360发布面向未来的EDR,全方位守护政企用户终端安全
MFCC to audio, the effect should not be too funny >V
salesforce使用方法(salesforce authenticator下载)
简述controller,service,repository注解的用法(谈谈application.properties的作用)