检测哪个 JavaScript 函数正在更改加载时的页面元素?

发布于 2024-08-23 01:17:22 字数 207 浏览 5 评论 0原文

我有很多在页面加载时运行的 jquery,它导致我的元素之一消失(使其 style=display:none;)。我猜测 jquery hide() 函数被错误地应用于此元素,但我无法找出哪个语句导致它。

是否有任何 javascript、firebug 等函数或工具本质上充当 html 元素的断点/侦听器(也许我可以在浏览器中运行)?很高兴看到什么功能正在影响页面加载时的该元素。

I have lots of jquery that is running on page load and it's causing one of my elements to disappear (making it style=display:none;). I'm guessing the jquery hide() function is being applied to this element by mistake, but I can't find out which statement is causing it.

Is there any javascript,firebug,etc function or tool that will essentially act as a breakpoint/listener for the html element (perhaps one I can run in my browser)? It would be great to see what function is affecting that element on page load.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思慕 2024-08-30 01:17:23

哈!我刚刚找到了我想要的答案。 Firebug 在 HTML 选项卡上有一个“break on mutate”功能,可以显示 javascript 文件中的哪一行正在更改 html 元素。它位于 Firebug 1.5 中,今天发布的新 1.5.2 更新移动了该图标,所以我注意到了它并纯粹是运气好找到它!

http://www.softwareishard.com/blog/firebug /firebug-15-break-on-next/

感谢你们的尝试!

Hah! I just found the answer I wanted. Firebug has a "break on mutate" function on the HTML tab that will show you what line in the javascript file is changing an html element. It is in Firebug 1.5 and the new 1.5.2 update released today moved the icon, so I noticed it and found it purely by luck!

http://www.softwareishard.com/blog/firebug/firebug-15-break-on-next/

Thanks for your attempts guys!

葬心 2024-08-30 01:17:23

您可以找到使用 getter/setter 访问元素的位置。然而,setter 方法似乎不适用于 chrome...它适用于最新版本的雷区 [firefox beta],不过...所以你可以测试一下我猜 =)

myElement.style.__defineSetter__("backgroundColor", function(val)
{
  var cur = arguments.callee;
  var callLog = "";
  while(cur != null)
  {
   callLog = cur.caller + "\n" + callLog;
   //alert(cur.caller);
   cur = cur.caller;
  }
  alert(callLog);
 }
);

哦,但它不会让您实际“设置”变量。为此,您需要定义一个虚拟变量并对其进行设置。然后,当您定义 getter [使用 __defineGetter__] 时,您将返回该值

You can find where the element is being accessed with getters/setters. However, the setter method doesn't seem to work with chrome... it works with the latest version of minefield [firefox beta], though... so you could test it out I guess =)

myElement.style.__defineSetter__("backgroundColor", function(val)
{
  var cur = arguments.callee;
  var callLog = "";
  while(cur != null)
  {
   callLog = cur.caller + "\n" + callLog;
   //alert(cur.caller);
   cur = cur.caller;
  }
  alert(callLog);
 }
);

Oh, but it won't let you actually "set" the variable. to do that, you define a dummy variable and set that. Then, when you define your getter [with __defineGetter__] you return that value

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文