更改观察者事件新值

问题描述 投票:0回答:1

我正在学习使用Mutation观察器类,主要是在这里:https://javascript.info/mutation-observer

我知道如何监听属性的变化,以及如何使用attributeOldValue获取旧的属性值。但是我可以从同一事件中获取新的属性值吗?如果是这样,怎么办?谢谢

javascript mutation-observers
1个回答
2
投票

您可以直接从更改的对象中直接查询当前值。

// 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;

© www.soinside.com 2019 - 2024. All rights reserved.