我正在学习使用突变观察者类,主要在这里:https://javascript.info/mutation-observer
我知道如何监听属性的变化,以及如何使用attributeOldValue获取旧的属性值。但是我可以从同一事件中获取新的属性值吗?如果是这样,怎么办?谢谢
最佳答案
您可以直接从更改的对象中查询当前值。
// is element is an input
const newValue = document.getElementByID('myElement').value;
// or, if it is a any text element
const newValue = document.getElementByID('myElement').innerHTML;
此外,每个 MutationRecord
都有一个名为 target
的属性,其中包含有关更改对象的所有详细信息。因此,根据 MutationRecord.type
(它告诉我们发生了何种类型的更改),您可以从 MutationRecord.target
关于javascript - 突变观察者事件新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58175892/