我可以在 DOM 元素的所有更改上使用调试器中断吗?

发布于 2024-09-05 02:51:27 字数 154 浏览 5 评论 0原文

我真的很希望能够看到影响特定 DOM 元素的代码。

但我也非常希望不必查看所有 javascript 来搜索可能导致问题的引用/选择器。

有没有人有一种技术可以让浏览器调试器在对特定 DOM 元素进行任何更改时中断?我不介意它需要特定的浏览器或扩展程序才能工作。

I would really love to be able to see the code that is affecting a specific DOM element.

But I also would really love not to have to look through all my javascript searching for references/selectors that might be causing the issue.

Does anyone have a technique for causing a browser debugger to break on any changes to a specific DOM element? I don't mind it requiring a specific browser or extension to work.

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

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

发布评论

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

评论(2

闻呓 2024-09-12 02:51:27

这也是不需要在 Firebug 以及 Chrome 的开发工具(也许是其他工具,没有进一步检查)中编写任何脚本的情况下实现的。

在 Firebug 中:

  1. 转到 HTML 选项卡
  2. 右键单击​​要监视的元素
  3. 选择“在属性更改时中断”、“在子添加或删除时中断”或“在元素删除时中断”

在 Chrome 开发者工具中

  1. 转到元素选项卡
  2. 右键单击您要监视的元素
  3. 选择“中断...”,然后选择“子树修改”或“属性修改”或“节点删除”

我实际上在尝试接受的999答案后发现了这一点,但是给定的代码对我不起作用。此外,Chrome 能够监视任何 DOM 子树上的事件,这似乎非常好。

This is also doable without writing any script in Firebug as well as in Chrome's developer tools (maybe others, did not inspect further).

In Firebug:

  1. Go to HTML tab
  2. Right-click an element you'd like to monitor
  3. Choose "Break On Attribute Change", or "Break On Child Addition Or Removal", or "Break On Element Removal"

In Chrome Developer Tools

  1. Go to Elements tab
  2. Right-click an element you'd like to monitor
  3. Select "Break On ...", then choose "Subtree Modification", or "Attributes Modification", or "Node Removal"

I actually found this out after trying accepted answer of 999, however given code did not work for me. Additionally, Chrome's possibility to monitor events on any DOM subtree seems really nice.

在风中等你 2024-09-12 02:51:27

注意:以下事件在提出问题时非常有用,但已不再是最新的。推荐的替代方案是 MutationObservers,但它们仍处于成熟阶段

MDN 上的 MutationObserver< /a>


试试这个(在 Firefox 中,安装了 Firebug):

function breakOnChange(el) {

    if (!el.addEventListener) return;

    el.addEventListener('DOMAttrModified',
         function(DOMAttrModifiedEvent){debugger}, true);

    el.addEventListener('DOMNodeInserted',
         function(DOMNodeInsertedEvent){debugger}, true);

    el.addEventListener('DOMNodeRemoved',
         function(DOMNodeRemovedEvent){debugger}, true);

}

// Usage:
breakOnChange(someDomNode);

Note: The events below were great when the question was asked, but are no longer current. The recommended alternative is MutationObservers, but those are still maturing

MutationObserver on MDN


Try this (in Firefox, with Firebug installed):

function breakOnChange(el) {

    if (!el.addEventListener) return;

    el.addEventListener('DOMAttrModified',
         function(DOMAttrModifiedEvent){debugger}, true);

    el.addEventListener('DOMNodeInserted',
         function(DOMNodeInsertedEvent){debugger}, true);

    el.addEventListener('DOMNodeRemoved',
         function(DOMNodeRemovedEvent){debugger}, true);

}

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