当前位置:网站首页>三个点语法和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(); 停止观察
边栏推荐
- eric6教程(电脑的配置基本知识)
- vscode中写markdown格式笔记的配置过程和相关语法
- Security思想项目总结
- XYplorer 23多语言,最好的管理软件之一
- RandLA-Net复现记录
- [100 Solidity Skills] 1. Contract reentrancy attack
- 【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1
- 自适应控制——仿真实验一 用李雅普诺夫稳定性理论设计自适应规律
- Mysterious APT Attack
- OC-ARC (Automatic Reference Counting) automatic reference counting
猜你喜欢

Re16: Read the paper ILDC for CJPE: Indian Legal Documents Corpus for Court Judgment Prediction and Explanation

async.js入门
![【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?](/img/f3/b9256fc04d1c9e15c74d2fc14db0fb.png)
【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?

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

第3章 信息收集
![[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 
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?

Selected System Design | Design of CAN Bus Controller Based on FPGA (with Code)

Materialist Dialectics - Conditionalism

jmeter接口压力测试-(二)
随机推荐
OC-关于alloc和dealloc(还没开始写)
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
类和对象—6个默认成员函数
MySQL | Subqueries
RandLA-Net复现记录
xshell使用技巧(赚分享平台怎么样)
Materialist Dialectics - Conditionalism
[AGC] Growth Service 2 - In-App Message Example
Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
Beyond Stream Processing !第四届实时计算 Flink 挑战赛启动,49 万奖金等你来拿!
Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
Telerik2022 R2,有效的自动化测试
In the robot industry professionals, Mr Robot industry current situation?
salesforce使用方法(salesforce authenticator下载)
OC-ARC (Automatic Reference Counting) automatic reference counting
Quick Start Tutorial for flyway
js对数组操作移动进行封装
【AGC】增长服务2-应用内消息示例
Database dirty reads, non-repeatable reads, phantom reads and corresponding isolation levels
Basemap和Seaborn