当前位置:网站首页>三个点语法和DOM观察者
三个点语法和DOM观察者
2022-08-08 11:53: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(); 停止观察
边栏推荐
- 宝塔实测-TinkPHP5.1框架小程序商城源码
- MySQL安装及使用
- 关于win下面Celery服务报 Process 'Worker' exited with 'exitcode 1' [duplicate]
- 轻量级接口自动化框架(jmeter+ant+jenkins)
- 如何在go重打印函数调用者信息Caller
- EZVIZ and Xiaomi compete against smart cameras
- Combining "xPlus" to discuss the innovation and change of software architecture
- 微服务负载均衡器Ribbon实战
- 写个 shell 玩 数字炸弹
- Optional常用方法解析
猜你喜欢

(kali - elevated privileges 】 【 4.2.4) social engineering toolkit: remote control trojans use, set up and use

3 million tenders!Qingdao Medical Security Bureau host database middleware operation and maintenance service project

海外邮件发送指南(一)

写个 shell 玩 数字炸弹

结合“xPlus”探讨软件架构的创新与变革

软件测试之测试代表用户

大缓存更强劲,搭载AMD Milan-X的浪潮GPU服务器NF5468A5深度评测

Mobile adaptation method of vw/vh - vw/vh instance - analog B stand mobile home page - get style tutorial video

贵州酒店集团特产券解析

刷题《剑指Offer》day12
随机推荐
day02 -DOM—高级事件(注册事件、事件监听、删除事件、DOM事件流、事件对象、阻止默认行为、阻止事件冒泡、事件委托)—常用鼠标事件—常用的键盘事件
Codeblocks安装与配置教程
ReentrantLock原理,ReentrantLock和synchronized区别
Geoffrey Hinton:深度学习的下一个大事件
如何使用shell来进行版本管理-以iptables为例
dedecms支持Word图文自动粘贴
(原创)[C#] GDI+ 之鼠标交互:原理、示例、一步步深入、性能优化
力扣(LeetCode)219. 存在重复元素 II(2022.08.07)
神经网络分类
在半小时内从无到有开发并调试一款Chrome扩展(Chrome插件/谷歌浏览器插件)
一条SQL在MySQL中是如何执行的
一起学习集合框架之 TreeSet
leetcode 1584. 连接所有点的最小费用
八、排序与搜索
(kali - elevated privileges 】 【 4.2.4) social engineering toolkit: remote control trojans use, set up and use
LeetCode_487_最大连续1的个数Ⅱ
学习与尝试 --&gt; 事件风暴
PG核心篇--物理存储结构
【力扣】两数相加
大缓存更强劲,搭载AMD Milan-X的浪潮GPU服务器NF5468A5深度评测