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

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

问题描述

我有一个元素通过JavaScript应用样式。我不知道到底在哪里;有没有办法检查Firebug来显示element.style实际来自哪里?

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?

推荐答案

确保它被设置在内联 style 上,而不是样式表规则的结果,您可以使用非标准Mozilla watch() method:

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';

您可以将 debugger; 函数,并在Firebug中查找调用堆栈,以查看触发更改的位置。

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天全站免登陆