我有一个简单的MutationObserver设置作为测试。HTML有一个span,它的文本内容每秒更新一次(还有一个用于消息的div):MutationObserver设置为监视.tester并在观察到变化时将文本写入#msgdiv。同时,setInterval()每秒运行一次以更改.tester中的文本:vartarget=document.querySelector('.tester');varobserver=newMutationObserver(function(mutations){mutations.forEach(function(mutation){console.
直到最近我还认为childList:true在MutationObserver将在添加/删除子节点时使用例如来自至和characterData:true将在观察到的元素内的文本发生变化时使用至withsometext.Itturnsoutthatfortextchangetobeobserved需要添加childList:true.谁能想到characterData没有childList会被使用吗?它有什么用? 最佳答案 您可以直接观察一个文本节点。在这种情况下,您不需要观察childList。在许多情况下它可能有用,例如在cont
直到最近我还认为childList:true在MutationObserver将在添加/删除子节点时使用例如来自至和characterData:true将在观察到的元素内的文本发生变化时使用至withsometext.Itturnsoutthatfortextchangetobeobserved需要添加childList:true.谁能想到characterData没有childList会被使用吗?它有什么用? 最佳答案 您可以直接观察一个文本节点。在这种情况下,您不需要观察childList。在许多情况下它可能有用,例如在cont