我正在尝试调试一些 JavaScript,我想找出当我将鼠标悬停在某个 div 元素上时会执行哪些代码(我不知道是哪一段代码,因为没有直接的“onmouseover” - 我认为有一个jQuery 选择器在某处吗?)。
通常我会使用开发者工具/Firebug 提供的“Break All”/“Break On Next”功能,但我的问题是其他代码(股票代码、鼠标移动监听器等)会立即被捕获。
我想做的是告诉调试器忽略某些 JavaScript 文件或单独的行,这样它就不会在我不感兴趣或已排除的代码上停止。有什么方法可以在 IE 中实现这一点(吐,吐!) - 或者你能建议更好的方法吗?
I'm trying to debug some JavaScript, I want to find out what code gets executed when I hover over a certain div element (I've got no idea which bit of code, because there's no direct 'onmouseover' - I think there's a jQuery selector in place somewhere?).
Usually I'd use the "Break All" / "Break On Next" facility provided by Developer Tools / Firebug, but my problem is that other code (tickers, mouse movement listeners etc.) immediately gets caught instead.
What I'd like to do is tell the debugger to ignore certain JavaScript files or individual lines, so that it won't stop on code I'm not interested in or have ruled out. Is there any way to achieve that in IE (spit, spit!) - or could you suggest a better approach?
发布评论
评论(6)
在 FireFox 中,此功能称为 “黑匣子” 将在 FireFox 25 中提供。它可以让我们完全满足您的需求。
尽管查找/配置比较困难,但 Chrome (v30+) 也引入了此功能。这被称为“跳过具有特定名称的源”,Collin Miller 在描述如何配置方面做得非常出色。
通常我会在这里放置答案和操作方法而不是链接,但最终我会复制科林的帖子。
In FireFox this feature is called "Black boxing" and will be available with FireFox 25. It let's do exactly what you where looking for.
This feature was also introduced to Chrome (v30+) although it's tougher to find/configure. It's called "skip through sources with particular names" and Collin Miller did an excellent job in describing how to configure it.
Normally I'm for putting answers and howtos here instead of links but it would just end in me copying Collin's post.
您似乎正在寻找视觉事件。
Looks like you're looking for Visual Event.
您可能想看看 Paul Irish 的 Re- Chrome 开发者工具简介,特别是时间轴部分(从视频中大约 15 分钟开始)。
您可以开始记录所有 JavaScript 事件 - 函数执行(使用源代码行等)并根据事件进行调试被解雇了。 google IO 演讲中还隐藏了其他非常方便的调试工具,也可以帮助您解决这个问题。
You might want to take a look at Paul Irish's Re-Introduction to the Chrome Developer Tools, in particular the Timeline section (starts around 15 minutes into the video.)
You can start recording all javascript events - function executions (with source lines etc) and debug based on what events fired. There are other really handy debugging tools hiding in that google IO talk that can help you solve this problem as well.
如果您非常确定它是一个 jQuery 事件处理程序,您可以尝试查看 jQuery 事件。
这将覆盖所有点击处理程序(替换为您感兴趣的类型)并在调用每个事件处理程序之前注销某些内容:
然后尝试直接通过 jQuery 调用事件类型以排除该类型:
If you're pretty sure it's a jQuery event handler you can try to poke around with the jQuery events.
This will overwrite all the click handlers (replace with the type you're interested in) and log out something before each event handler is called:
Then try calling the event type directly through jQuery to rule out that type:
您可以在 Firefox 中使用 JavaScript Deobfuscator 扩展: https://addons.mozilla.org/addon/javascript -反混淆器/。它使用与 Firebug 相同的调试 API,但显示的结果不同。
在“执行的脚本”选项卡中,它将显示所有正在运行的代码。如果某些不相关的代码也在执行,通常很容易跳过。但您也可以调整默认过滤器以限制显示的代码量。
You can use JavaScript Deobfuscator extension in Firefox: https://addons.mozilla.org/addon/javascript-deobfuscator/. It uses the same debugging API as Firebug but presents the results differently.
In the "Executed scripts" tab it will show you all code that is running. If some unrelated code is executing as well it is usually easy enough to skip. But you can also tweak the default filters to limit the amount of code being displayed.
如果使用 IE 7.0 及以上版本,您应该拥有可以调试的开发人员工具栏。只需在需要的地方使用断点,其余代码将不会停止。
或者,您也可以定义其他应用程序(例如 Interdev/Visual Studio.net)以进行调试。
If using are using IE 7.0 onwards, you should have developer toolbar from where you can debug. Just use breakpoint where you need, rest of the code will not stop.
Alternatavely you can define other applications like Interdev/ Visual Studio.net for debugging purpose too.