如何找到哪些JavaScript正在更改元素的风格? [英] How do I find which JavaScript is changing an element's style?

查看:104
本文介绍了如何找到哪些JavaScript正在更改元素的风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过JavaScript应用风格的元素。我不知道究竟在哪里有没有办法检查Firebug来显示element.style实际来自哪里?

解决方案

如果你是确定它是内置的样式而不是样式表规则的结果,您可以使用非标准的Mozilla watch()方法:

  document.body.style.watch('color',function(name,v0,v1){
alert(name +':'+ v0 +' - >'+ v1);
});
document.body.style.color ='red';

您可以在观察者中放入调试器; 功能,并在Firebug中查找调用堆栈,以查看更改被触发的位置。


I have an element that's getting styles applied via JavaScript. I'm not sure exactly where; is there a way to check Firebug to show where the "element.style" is actually coming from?

解决方案

If you're sure it's being set on the inline style and not as a consequence of a stylesheet rule, you can detect changes using the non-standard Mozilla watch() method:

document.body.style.watch('color', function(name, v0, v1) {
    alert(name+': '+v0+'->'+v1);
});
document.body.style.color= 'red';

You can put debugger; in the watcher function and look up the call stack in Firebug to see where the change was triggered.

这篇关于如何找到哪些JavaScript正在更改元素的风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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