在 ASP.NET 中调试 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10573819/
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
Debug JavaScript in ASP.NET
提问by NewToNet
I needed to debug my javascript functions written in asp.net.
我需要调试我用 asp.net 编写的 javascript 函数。
I am currently using chrome but its not going to the break point. If i put alert('Some message')
. I can see message displayed.
我目前正在使用 chrome,但它不会到断点。如果我把alert('Some message')
. 我可以看到显示的消息。
If someone has any idea how to use debugger for JavaScript in ASP.NET please let me know.
如果有人知道如何在 ASP.NET 中使用 JavaScript 调试器,请告诉我。
采纳答案by Adil
To Debug in chrome you need to do two things
要在 chrome 中进行调试,您需要做两件事
- Write debugger the place where you want to start debugging.
- Before the execution of script open developer tool (by pressing ctrl + shift + i)
- 在要开始调试的地方编写调试器。
- 在执行脚本之前打开开发者工具(按 ctrl + shift + i)
Now when control of execution to statement where you wrote debugger the execution is paused for you to debug.
现在,当控制执行到您编写调试器的语句时,执行将暂停以供您调试。
Here is an example for you to learn, Follow the instruction given in comments. How to debug in chrome
这是一个供您学习的示例,请按照评论中给出的说明进行操作。如何在chrome中调试
回答by Nudier Mena
Try to debug your code with Internet Explorer, you can do it like this, place the debugger keyword before the code you want debug.
尝试使用 Internet Explorer 调试您的代码,您可以这样做,将 debugger 关键字放在您要调试的代码之前。
<script type="text/javascript">
function s() {
//enable the debugger feature.
debugger;
var alert = "this is a debugger test";
alert(alert);
}
</script>
回答by Emmie Lewis-Briggman
Use FireBug! It is great! It gives you a little bit more power than traditional debugging. http://getfirebug.com/errors
使用FireBug!太好了!它为您提供比传统调试更多的功能。 http://getfirebug.com/errors
Status bar error indicator
On the right side of the Firefox browser's status bar you will see a little green icon. This is Firebug's way of telling you that everything is A-Ok. When that icon turns into a red "x", things aren't so peachy.
Click the "x" to open the Firebug error console which will show you all of the errors that have occurred on the page.
No error soup
Most browsers report errors by dumping them all into one big window that includes the problems with every web page you've ever visited. Firebug is kinder than that; it shows you only the errors for the page that you're looking at.
Jump to the debugger
Every error report has a link on its right side that points to the file and line number where the error occurred. Clicking this link will take you right to the Firebug JavaScript debugger or CSS inspector so that you can get started on solving the problem right away.
Some errors also include the actual snippet of source that contains the error, which is also a link to the original file.
状态栏错误指示
在 Firefox 浏览器状态栏的右侧,您会看到一个绿色的小图标。这是 Firebug 告诉您一切正常的方式。当那个图标变成一个红色的“x”时,事情就不那么好了。
单击“x”打开 Firebug 错误控制台,它将显示页面上发生的所有错误。
没有错误汤
大多数浏览器通过将错误全部转储到一个大窗口中来报告错误,该窗口包含您访问过的每个网页的问题。Firebug 比那更友善;它只显示您正在查看的页面的错误。
跳转到调试器
每个错误报告的右侧都有一个链接,指向发生错误的文件和行号。单击此链接会将您直接带到 Firebug JavaScript 调试器或 CSS 检查器,以便您可以立即开始解决问题。
一些错误还包括包含错误的实际源代码片段,它也是原始文件的链接。
回答by abatishchev
From my experience Visual Studio can't debug Managed Code and JavaScript in the same time.
根据我的经验,Visual Studio 无法同时调试托管代码和 JavaScript。
This mean that when you start an ASP.NET project in debug mode within Visual Studio, it will start web server, attach to it, then IE (or another browser) and attach to it. But JS breakpoint will not be hit.
这意味着当您在 Visual Studio 中以调试模式启动 ASP.NET 项目时,它将启动 Web 服务器,附加到它,然后是 IE(或其他浏览器)并附加到它。但是不会命中JS断点。
But when you start a project without debug and attach to IE manually - those breakpoint will be hit.
但是当你在没有调试的情况下启动一个项目并手动附加到 IE 时 - 这些断点将被击中。
回答by SLaks
Visual Studio can only debug Javascript if it's attached to an instance of IE.
Visual Studio 只能调试附加到 IE 实例的 Javascript。
You should use Chrome's developer tools, which include a Javascript debugger.
您应该使用 Chrome 的开发人员工具,其中包括一个 Javascript 调试器。