如果更改DOM,您如何做某事? [英] How do you do something if the DOM is changed?
本文介绍了如果更改DOM,您如何做某事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测文档何时更改?
How can I detect when the document changes?
我知道我可以这样做:
var lastHTML = document.body.innerHTML;
setInterval(function() { if(document.body.innerHTML != lastHTML) { DOMupdated() } }, 500);
但是我可以设置一个事件处理程序,比如onchange吗?
But is there an event handler I can put in place, like onchange?
推荐答案
有旧的 DOM Mutation Events ,还有新的 DOM Mutation Observers 。
为了快速浏览它们(以及为什么更新[更复杂]的API更好),请查看以下帖子:
For a quick overview of them both (and why the newer [more complex] API is better), check out this post:
PS不要错过那里的评论...
P.S. Don't miss the comments there...
这篇关于如果更改DOM,您如何做某事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文