问题描述
MutationRecord.addedNodes返回带有检测到的节点的NodeList,该节点已添加到我的文档中.当我使用obj.appendChild()方法时,mutationObserver会检测到它,并以节点列表[node]的形式返回MutationRecord.addedNodes中的这个ONE节点.当我在循环中使用.appendChild()时,mutationObserver会触发与循环次数相同的次数.
MutationRecord.addedNodes returns NodeList with nodes detected as added in my document. When I use obj.appendChild() method, mutationObserver detects it and returns this ONE node in MutationRecord.addedNodes as nodelist [node]. When I use .appendChild() in loop, mutationObserver fires as many times as the number of loops amounts.
我只是想知道是否有任何情况时mutationOvserver会检测到同时添加的多个节点并触发ONCE并将MutationRecord.addedNodes中的那些节点作为一个节点列表[node,node,node,...]返回吗?/p>
I'm just wondering if there is any case when mutationOvserver will detect more than one node added simultaneously and fire ONCE and return those nodes in MutationRecord.addedNodes as ONE nodelist [node,node,node,...]?
推荐答案
由规范一个 appendChild
对应于一个单节点 addedNodes
数组.
Judging by the spec one appendChild
corresponds to a single-node addedNodes
array.
addedNodes
通常在初始页面加载期间包含许多节点,并且自然地,如果通过 insertAdjacentHTML
或 document的一次操作在js代码中插入了许多节点.write
或 .innerHTML
或 .outerHTML
或 DocumentFragment ,其中包含许多节点.
addedNodes
usually contains many nodes during the initial page load and, naturally, if many nodes were inserted by js code in one operation via insertAdjacentHTML
, or document.write
, or .innerHTML
, or .outerHTML
, or DocumentFragment with many nodes.
这篇关于MutationRecord.addedNodes节点列表(mutationObserver)中返回的节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!