visual-studio 如何在 Visual Studio 2005 中调试 JavaScript?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8398/
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
How do I debug JavaScript in Visual Studio 2005?
提问by Bryan Denny
I just saw this mentioned in Stack Overflow question Best WYSIWYG CSS editorand didn't know it could be done. I'm a Visual Studio newbie, so how do you do it?
我刚刚在 Stack Overflow 问题Best WYSIWYG CSS editor 中看到了这一点,但不知道可以做到。我是 Visual Studio 的新手,你是怎么做的?
Is there a separate debugger for JavaScript? I know how to work the one for code-behind pages... I usually use Firebug to deal with debugging JavaScript code.
是否有单独的 JavaScript 调试器?我知道如何为代码隐藏页面工作...我通常使用 Firebug 来处理调试 JavaScript 代码。
I'm using Visual Studio 2005.
我正在使用Visual Studio 2005。
采纳答案by brendan
I prefer using Firebugfor projects I can't use Visual Studio 2008on.
我更喜欢将Firebug用于我不能在Visual Studio 2008上使用的项目。
回答by ScottKoon
To debug in Visual Studio 2005, make sure that "disable script debugging" is unchecked. Then load your webpage in Internet Explorer. From the debug menu inside of Visual Studio 2005, select "Attach to process" and pick the instance of Internet Explorer that has your web page loaded.
要在 Visual Studio 2005 中进行调试,请确保未选中“禁用脚本调试”。然后在 Internet Explorer 中加载您的网页。从 Visual Studio 2005 内的调试菜单中,选择“附加到进程”并选择加载了您的网页的 Internet Explorer 实例。
Alternatively, the Firebugteam has been working on a "lite" version that you can include either as a script in your page or by launching it via a bookmarklet from your browser. It doesn't provide the full debugger that Firebug does, but it gives you a console and a command line from which you can inspect variables and log things to the console.
或者,Firebug团队一直在开发“精简版”版本,您可以将其作为脚本包含在页面中,也可以通过浏览器中的书签启动它。它没有提供 Firebug 提供的完整调试器,但它为您提供了一个控制台和一个命令行,您可以从中检查变量并将内容记录到控制台。
回答by Christian Hagelid
TechRepublic has a good walk through - see Visual Studio 2008 simplifies JavaScript debugging.
TechRepublic 有一个很好的演练 - 请参阅Visual Studio 2008 简化 JavaScript 调试。
回答by Jon Limjap
Visual Studio 2008 ASP.NET projects has debugging enabled by default. You can set breakpoints within your .js file while the website/web app project is run in the ASP.NET debug server.
Visual Studio 2008 ASP.NET 项目默认启用调试。当网站/Web 应用程序项目在 ASP.NET 调试服务器中运行时,您可以在 .js 文件中设置断点。
回答by David Basarab
Just make sure you have 'Disable Script Debugging' unchecked, and just hit F5 to start debugging in VS2005 or 2008.
只需确保未选中“禁用脚本调试”,然后按 F5 即可在 VS2005 或 2008 中开始调试。
I would also note that if you have your JavaScript inside the .aspx page you will have to find it via the script explore. However if you have it in a separate .js file you can just put a break point on it like you would any .cs file.
我还要注意的是,如果你在 .aspx 页面中有你的 JavaScript,你将不得不通过脚本探索找到它。但是,如果您将它放在单独的 .js 文件中,则可以像处理任何 .cs 文件一样在其上放置一个断点。
回答by Dave Ward
I usually use Firebug to deal with debugging JS.
我通常使用 Firebug 来处理调试 JS。
Unless you need to debug in IE, there's no need to stop using Firebug. It works with JavaScript in ASP.NET pages just as well as it does with any other type of page.
除非你需要在 IE 中调试,否则没有必要停止使用 Firebug。它在 ASP.NET 页面中与 JavaScript 一起工作,就像在任何其他类型的页面上一样。
Visual Studio's JavaScript debugging is alright, but really cannot compete with the full range of client-side information that Firebug aggregates.
Visual Studio 的 JavaScript 调试还可以,但确实无法与 Firebug 聚合的所有客户端信息竞争。
回答by Dave Ward
Debugging client JavaScript code in Visual Studio 2005:
在 Visual Studio 2005 中调试客户端 JavaScript 代码:
Add the following code to the start of the JavaScript code:
将以下代码添加到 JavaScript 代码的开头:
debugger
回答by Ray
In Internet Explorer, select View-> Script Debugger-> Open. That should do it.
在 Internet Explorer 中,选择View-> Script Debugger-> Open。那应该这样做。
回答by Jason Bunting
Usually you know where you are having problems, so you can set a breakpoint in your JavaScript code by placing the keyword "debugger;" on a line in your JavaScript code (obviously without the quotes) to set a breakpoint.
通常您知道问题出在哪里,因此您可以通过放置关键字“调试器”在 JavaScript 代码中设置断点;在 JavaScript 代码中的一行(显然没有引号)上设置断点。
When you get to it in Internet Explorer, it will ask you if you want to debug and prompt you to choose a debugger from a list, hopefully you will see Visual Studio in that list (both a new instance as well as your currently-running instance) - if you are using Firefoxwith Firebug, it will automatically stop execution on that line and you will be within the Firebug debugger, not Visual Studio.
当您在 Internet Explorer 中访问它时,它会询问您是否要调试并提示您从列表中选择一个调试器,希望您能在该列表中看到 Visual Studio(新实例以及您当前运行的实例)实例) - 如果您将Firefox与Firebug一起使用,它将自动停止在该行上的执行,并且您将位于 Firebug 调试器中,而不是 Visual Studio。
You will want to do the following to setup Internet Explorer for doing this - from within Internet Explorer, follow this menu path: Tools> Internet Options> Advanced Tab> Uncheckthe "Disable Script Debugging" options.
您将需要执行以下操作来设置 Internet Explorer 以执行此操作 - 从 Internet Explorer 中,按照此菜单路径:工具> Internet 选项>高级选项卡>取消选中“禁用脚本调试”选项。
回答by Johnno Nolan
Yeah using Microsoft Script Editoris a an option if you have Office XP or Office 2003 installed. In IE uncheck Disable Script debugging (Internet Explorer) and Disable Script debugging (Other).
是的,如果您安装了 Office XP 或 Office 2003,则可以选择使用Microsoft 脚本编辑器。在 IE 中取消选中禁用脚本调试(Internet Explorer)和禁用脚本调试(其他)。
Restart IE. In View menu you will have a new item, "script debugging", choose open. You will be given a choice of VS2005 or New instance of Microsoft Script Editor, choose that and give it a go.
重启IE。在查看菜单中,您将有一个新项目“脚本调试”,选择打开。您将可以选择 VS2005 或 Microsoft 脚本编辑器的新实例,选择并试一试。
Edit: try thislink for a tutorial
编辑:试试这个链接的教程

