跟踪 Javascript 代码的最佳方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6179073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to trace Javascript code
提问by testndtv
What is the best way to debug Javascript code using any tool..i.e. i want to know when a button is clicked, what all JS code gets executed...
使用任何工具调试 Javascript 代码的最佳方法是什么..ie 我想知道当一个按钮被点击时,所有 JS 代码都被执行了...
I wanted to test in Firefox and Safari..Already tried Firebug, but want to know if there is any better way..
我想在 Firefox 和 Safari 中进行测试..已经尝试过 Firebug,但想知道是否有更好的方法..
Also more importantly i want to know "how" exactly to debug the code?
更重要的是,我想知道“如何”调试代码?
Also is it possible to print the complete JS code that gets called when I say press a button?
当我说按下按钮时,是否可以打印完整的 JS 代码?
采纳答案by thaddeusmt
This post, using FireFox's FireBug and jQuery, might help you detect and capture all of the events bound to a button so you can tell what JS code is run when the button is clicked:
这篇文章使用 FireFox 的 FireBug 和 jQuery,可以帮助您检测和捕获绑定到按钮的所有事件,以便您可以判断单击按钮时运行的 JS 代码:
How to debug JavaScript/jQuery event bindings with Firebug (or similar tool)
回答by RobinJ
I always use the integrated web inspector tool from Google Chrome (you know, right-click, Inspect element). It works quite well for me, and has all the functions I need.
我总是使用 Google Chrome 中的集成网络检查器工具(你知道,右键单击,Inspect element)。它对我来说效果很好,并且具有我需要的所有功能。
回答by Mikhail Nikalyukin
Chrome Developer Console + Firefox Firebug
Chrome 开发者控制台 + Firefox Firebug
回答by fvu
Chrome Developer Console + Firefox Firebug of course (and Firebug Lite in IE), but also check out Visual Event, a bookmarklet that show you a highly visual overview of events attached to elements of your page.
当然,Chrome 开发者控制台 + Firefox Firebug(以及 IE 中的 Firebug Lite),但也可以查看Visual Event,这是一个书签,可向您显示附加到页面元素的事件的高度可视化概览。
回答by Gleno
Well, I think that the best method is using Visual Studio and hooking it with Internet Explorer. As many others have pointed out, the browser built-in tools are great, but visual studio lets you debug javascript code and edit it with same application. The downside is that you must use Internet Explorer, but personally I don't find it to be such a big problem.
嗯,我认为最好的方法是使用 Visual Studio 并将其与 Internet Explorer 挂钩。正如许多其他人指出的那样,浏览器内置工具很棒,但 Visual Studio 允许您调试 javascript 代码并使用相同的应用程序对其进行编辑。缺点是您必须使用 Internet Explorer,但我个人认为这不是一个大问题。