1 回答

TA贡献1798条经验 获得超7个赞
为此,您需要使用MutationObserver。它监视 DOM 的更改(例如删除/添加类)并触发回调函数供您以任何您认为合适的方式使用。
// Select the node that will be observed for mutations
var targetNode = document.getElementById('gridview');
// Options for the observer (which mutations to observe)
var config = { attributes: true };
// Callback function to execute when mutations are observed
var callback = function(mutationsList, observer) {
for(var mutation of mutationsList) {
if (mutation.type == 'attributes') {
// Triggers when an attribute like 'class' is modified
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
};
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
稍后,您可以停止观察
observer.disconnect();
添加回答
举报