如何监控 DOM 的变化? [英] How do I monitor the DOM for changes?

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

问题描述

有没有办法(使用 jQuery 或其他方式)来监视 DOM 的插入、删除、样式更新等情况?

Is there a way - using jQuery or otherwise - to monitor the DOM for insertions, deletions, updates to styles, etc?

推荐答案

参见此处的MutationEvent"元素:https://developer.mozilla.org/en/DOM/DOM_event_reference 但这些已被弃用.

See "MutationEvent" elements in here: https://developer.mozilla.org/en/DOM/DOM_event_reference but those are deprecated.

jQuery 现在提供了一种将事件附加到与选择器对应的现有和未来元素的方法:http://docs.jquery.com/Events/live#typefn

jQuery now features a way to attach events to existing AND future elements corresponding to a selector: http://docs.jquery.com/Events/live#typefn

这可能是您在缺乏正确的 DOM 节点修改信息时可以使用的一个技巧.

It may be a trick you could use for lack of proper DOM Node modification info.

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

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