简体   繁体   English

找出更改页面中特定html内容的javascript代码的最佳方法是什么?

[英]What's the best way to figure out which javascript code that change specific html content in page

我在我的网页上有<p>标签,我试图找出在此元素中添加文本的JavaScript函数,是否有任何特定的方法在chrome中添加此标记上的侦听器以找出在此标记上写入的脚本?

The most direct (low noise) way uses a sync pause that lets you poke around in the whole call stack: 最直接(低噪音)方式使用同步暂停,让您在整个调用堆栈中徘徊:

  1. Open chrome's devtools. 打开chrome的devtools。
  2. Right-click the element in the devtools "Elements" tab to reveal the context menu 右键单击devtools“Elements”选项卡中的元素以显示上下文菜单
  3. Choose Break On... > Subtree Modifications. 选择Break On ...> Subtree Modifications。

Once the element's "innerHTML" changes, the script execution will pauses and you can view the whole call stack in the "Sources" tab, including whatever function requested the DOM change. 一旦元素的“innerHTML”发生变化,脚本执行将暂停,您可以在“Sources”选项卡中查看整个调用堆栈,包括请求DOM更改的任何函数。

Certain DOM modifications like animation libraries can use a setTimeout or callback that discards much of the call stack that lead up to the change, and in those cases, a Profile might be more interesting, since the animation function should stand out like a sore thumb in a "Heavy" view. 某些DOM修改(如动画库)可以使用setTimeout或回调来丢弃导致更改的大部分调用堆栈,在这种情况下,Profile可能会更有趣,因为动画功能应该像一个痛苦的拇指一样突出一个“沉重”的观点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找出哪些代码导致失控 DOM 节点创建的好方法是什么? - What's a good way to figure out which code is causing runaway DOM node creation? 给定html字符串,最好的方法是仅剥离javascript中的锚HTML标记? - What's the best way to strip out only the anchor HTML tags in javascript, given a string of html? 将wordpress插件挂钩到单个页面以呈现一些html / javascript内容的最佳方法是什么? - What is the best way to hook wordpress plugin to a single page in order to render some html/javascript content? 在JavaScript中格式化HTML,CSS和JavaScript代码的最佳方法是什么? - What's the best way to format HTML, CSS and JavaScript code within a JavaScript 确定哪个下拉菜单项应处于活动状态的最佳方法是什么? - What is the best way to figure out which drop down menu item should be active? 在页面加载时将服务器端HTML转换为Javascript MVC的最佳方法是什么? - What's the best way to convert server side HTML into a Javascript MVC on page load? Angular-在选项卡内容内加载html页面的最佳方法 - Angular - Best way to load html page inside tab's content 在javascript中打印带点的长数字的最佳方法是什么? - What's the best way to print out a long number with dots in javascript? 删除 JavaScript 数组中特定字符的最佳方法是什么? - What's the best way to delete specific characters in a JavaScript array? Rails页面特定的JavaScript:什么是最佳实践? - Rails page-specific JavaScript: What's the best practice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM