DOM突变事件更换 [英] DOM mutation events replacement

查看:173
本文介绍了DOM突变事件更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于DOM突变被w3c标记为不赞成(见 http://www.w3.org/TR/DOM-Level-3-Events/#events-modeevents ),是否有(快速)替代方法来检测DOM中的属性修改? p>

Since DOM mutation is marked as deprecated by the w3c (see http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents), is there an (fast) alternative way to detect attribute modification in the DOM ?

推荐答案

据我所知,没有其他的(还),所以你被困在 DOMAttrModified 它只支持在Firefox和Opera。在IE中,您有 onpropertychanged 事件,但没有办法在Chrome / Safari中获得类似的功能。根据您要完成的内容和您所针对的浏览器,您可以执行一些操作:

As far as I know there is no alternative (yet) so you are stuck with DOMAttrModified which is only supported in Firefox and Opera. In IE you have the onpropertychanged event but there is no way to get similar functionality in Chrome/Safari. There are a number of things you could do depending on what you are trying to accomplish and the browsers you are targetting:


  • 定义getter和setter到您要监视的属性

  • 覆盖方法,如 document.createAttribute attributes.setNamedItem ,...

  • define getters and setters to the attributes you want to monitor
  • override methods like document.createAttribute, attributes.setNamedItem, ...

我一直在使用跨浏览器解决方案,但没有多少成功。你应该远离突变事件,因为它们不是跨浏览器,而且很慢。
有很好的理由不推荐使用它们。如果您想了解更多信息,请阅读以下信息:

I've been working on a cross-browser solution myself but without much success. You should stay away from mutation events all together since they are not cross-browser and very slow. There are good reasons why they are deprecated. If you want to learn more read this:

  • http://www.w3.org/2008/webapps/wiki/MutationReplacement
  • http://www.quirksmode.org/dom/events/ > W3C events
  • http://robertnyman.com/javascript/javascript-getters-setters.html

这篇关于DOM突变事件更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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