javascript - 通过 MutationObserver 遍历多个 addedNodes 并获取 target.innerText
问题描述
我正在处理每秒添加多个节点以及删除多个节点的页面。但我只对新添加的节点和其中的文本感兴趣。这是我的脚本
let mList = document.querySelector('._24tx'),
options = {
childList: true,
attributes: false,
characterData: true,
subtree: true,
attributeOldValue: false,
characterDataOldValue: true
},
observer = new MutationObserver(mCallback);
function mCallback(mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length > 0) {
for (var i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.target.innerText != '') {
console.log(mutation.target.innerText);
}
}
}
}
);
}
observer.observe(mList, options);
我收到单个节点的重复条目。如何定位每个addedNodes并获取它们的innerText?
解决方案
推荐阅读
- angular - AppController for AngualrDart&Flutter
- ruby-on-rails-4 - 为语音呼叫集成问题生成 twilio 功能令牌
- powershell - 使用 Get-ChildItem -Exclude 排除文件夹
- javascript - Angularjs - 加载整个应用程序后如何运行代码?
- javascript - 如何在 reactJS/Javascript 分页中的页码之间添加点
- java - 我打开 zip 时清单包含的内容与 Java 返回的内容之间存在差异
- ionic-framework - 键盘打开时离子内容向上滚动问题
- javascript - 如何在Javascript中将对象数组的对象转换为对象数组
- java - 如何在gridLayout中居中元素
- hadoop - 如何将 RDBMS 数据与 HDFS 数据同步