如何识别何时改变DOM? [英] How to identify when the DOM has been changed?

查看:104
本文介绍了如何识别何时改变DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有内置的JavaScript / jQuery事件/函数?

解决方案

如果您必须检测到更改,则可以检查DOM突变事件。 DOM事件维基百科页面列出了所有这些。但是您应该知道它们在Internet Explorer中不受支持,并且在支持它们的浏览器中可能会频繁启动。蛮力的方法是使用 setTimeout 并自行检查更改。



我的经验表明,可以避免对DOM更改通知的需要。您能否提供更多有关您的具体要求的详细信息?


Is there a simple way to know when the DOM has been changed ?

Is there any built-in JavaScript/jQuery event/function for this ?

解决方案

If you must detect changes you can check the DOM mutation events. The DOM events wikipedia page lists them all. However you should know that they are not supported in Internet Explorer and may fire too often in the browsers that support them. A brute force approach is to use setTimeout and check for changes by yourself.

My experience shows though that the need for DOM change notifications can be avoided. Could you give more details about your exact requirements?

这篇关于如何识别何时改变DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆