4
我現在有代碼:DOMNodeInserted DOMNode與MutationObserverRemoved等價嗎?
$('.example').bind('DOMNodeInserted DOMNodeRemoved', function(event) {
....
});
這完美的作品,但它是不是很有效,至今已過時的。有什麼更好的方法來做到這一點?
我一直在調查MutationObserver,但這段代碼確實有用嗎?
它給出的錯誤「mutation.addedNodes
不是一個函數」我也需要我認識的removedNodes
。
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.className == 'example') {
....
}
});
});
});
observer.observe(document, {
childList: true,
subtree: true,
attributes: false,
characterData: false,
});
方法Wait我需要'document'是'.example'?因爲我想通知'.example'的任何子節點而不是'.example'本身 – maxisme
@Maximilian _「等待我需要文檔是.example?因爲我想要通知.example的任何子節點比.example本身「_是 – guest271314
@Maximilian查看更新後的帖子 – guest271314