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();
添加回答
舉報