在 Visual Studio 2010 中调试 JavaScript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5413937/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:06:04  来源:igfitidea点击:

Debug JavaScript in Visual Studio 2010?

javascriptvisual-studio-2010debugging

提问by Pete

Currently I am debugging my JavaScript using Firebug for Firefox. Is there anyway to debug javascript in Visual Studio 2010? The JavaScript isn't part of any Visual Studio project, it's just a .js file that will be linked to a static HTML page (it's to debug school assignments).

目前我正在使用 Firebug for Firefox 调试我的 JavaScript。无论如何要在 Visual Studio 2010 中调试 javascript?JavaScript 不是任何 Visual Studio 项目的一部分,它只是一个将链接到静态 HTML 页面(用于调试学校作业)的 .js 文件。

I did try searching and the results weren't any more recent than around a year ago. I'm hoping something has changed or there is a better workflow than notepad++ for HTML/JavaScript and Firebug for debugging.

我确实尝试过搜索,但结果并不比大约一年前更新。我希望有些东西已经改变,或者有比 notepad++ 更好的工作流程,用于 HTML/JavaScript 和 Firebug 用于调试。

回答by airbai

Use the JavaScript debugger keyword in IE.

在 IE 中使用 JavaScript 调试器关键字。

function onClickRow(detailUrl) {
    debugger;
}

When run your page in IE, a debug window will pop up, then select Visual Studio 11.

在 IE 中运行页面时,会弹出一个调试窗口,然后选择 Visual Studio 11。

回答by devi

To use debug in Internet Explorer, you need perform these steps:

要在 Internet Explorer 中使用调试,您需要执行以下步骤:

  • enable script debugging in IE (go to Internet options->advanced->browsing and uncheck 'Disable script debugging')
  • select view->external script debugger->break on next statement
  • 在 IE 中启用脚本调试(转到 Internet 选项->高级->浏览并取消选中“禁用脚本调试”)
  • 选择视图-> 外部脚本调试器-> 在下一条语句上中断

When next javascript statement will be reached, IE will show standard windows debugger selection dialog, when you can select instance of visual studio.

当到达下一个 javascript 语句时,IE 将显示标准的 Windows 调试器选择对话框,此时您可以选择 Visual Studio 的实例。

Update: With visual studio you can attach to browser process(e.g. iexplore.exe) and then debug

更新:使用 Visual Studio,您可以附加到浏览器进程(例如 iexplore.exe),然后进行调试

回答by Pete

This question gets a lot of views so for the sake of completeness I just wanted to mention that I've been using Chrome Developer Toolsfor a while now. It's been working great for me and is what I recommend now when people ask me this same question.

这个问题得到了很多观点,所以为了完整起见,我只想提一下,我已经使用Chrome 开发者工具有一段时间了。它对我来说效果很好,当人们问我同样的问题时,我现在推荐它。

回答by Mark Kahn

Yes, but only in IE. Basically just create a web-page project and hit run. It'll launch IE in debugger mode.

是的,但仅限于 IE。基本上只是创建一个网页项目并点击运行。它将在调试器模式下启动 IE。

回答by Snake Eyes

回答by Zymotik

If you installed VS 2012 and then uninstalled it, you may need to Re-Install Visual Studio 2010.

如果您安装了 VS 2012 然后又将其卸载,则可能需要重新安装 Visual Studio 2010。

Error you may get when trying to debug JavaScript:

尝试调试 JavaScript 时可能会遇到的错误:

---------------------------
Microsoft Visual Studio
---------------------------
Unable to attach to the crashing process. The correct version of pdm.dll is not registered. Repair your Visual Studio 2010 installation, or run 'regsvr32.exe "%CommonProgramFiles%\Microsoft Shared\VS7Debug\pdm.dll"'.
---------------------------
OK   
---------------------------

回答by Lynn Crumbling

If you want to try giving it a shot in IE, I posted about using the js debugger here: jQuery/Ajax content not appearing/loading in Explorer

如果您想尝试在 IE 中试一试,我在此处发布了有关使用 js 调试器的信息: jQuery/Ajax 内容未在资源管理器中显示/加载