如何使用 Netbeans 调试 JavaScript 代码?

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

How to debug JavaScript code with Netbeans?

javascriptdebuggingnetbeans

提问by lolveley

I am not experienced in developing web apps with NetBeans.

我没有使用NetBeans开发 Web 应用程序的经验。

I created an HTML5 project with existing sources (some HTML, JS and CSS files), the import seems to be OK, but I didn't manage to debug JavaScriptcode, because the "Debug project", "Debug file"and "Debug test file"menu items are always disabled.

我使用现有源(一些 HTML、JS 和 CSS 文件)创建了一个 HTML5 项目,导入似乎没问题,但我没有设法调试 JavaScript代码,因为“调试项目”“调试文件”“调试”测试文件”菜单项总是被禁用

What have I missed?

我错过了什么?

PS.: I downloaded a fresh version in November 2013.

PS.:我在 2013 年 11 月下载了一个新版本。

回答by ladar

HTML5 project is always debugging and running at the same time if you run it in any browser with NetBeans connector (check the browser switcher in toolbar). So once you run project/file, if some breakpoint should be hit, it will be. Therefore debug action is not enabled for HTML5 project, because it is the same as Run action.

如果您在任何带有 NetBeans 连接器的浏览器中运行 HTML5 项目,它总是同时调试和运行(检查工具栏中的浏览器切换器)。所以一旦你运行项目/文件,如果某个断点应该被击中,它就会被击中。因此,HTML5 项目没有启用调试动作,因为它与运行动作相同。

Basically it means you can debug JS in Chrome with NetBeans Connector, Embedded browser in IDE, Chrome on Android, Safari on iOS...

基本上这意味着您可以使用 NetBeans 连接器在 Chrome 中调试 JS,IDE 中的嵌入式浏览器,Android 上的 Chrome,iOS 上的 Safari...

回答by treefiddy

I also ran into issues when trying to debug JavaScript in a PHP project. I was using Chrome as my browser and had confirmed that the Netbeans Connector extension was installed and working in Chrome.

我在尝试在 PHP 项目中调试 JavaScript 时也遇到了问题。我使用 Chrome 作为我的浏览器,并确认 Netbeans 连接器扩展已安装并在 Chrome 中工作。

I could debug PHP without any issues. I could create a separate HTML5/JavaScript project and debug JavaScript without any problem. However, when I tried to set breakpoints on JavaScript code that was embedded in tags within the PHP file, I would get the little 'broken' breakpoints that everyone else references. When I selected the option to debug project, I could debug the PHP code, but the JavaScript breakpoints were never hit.

我可以毫无问题地调试 PHP。我可以创建一个单独的 HTML5/JavaScript 项目并毫无问题地调试 JavaScript。但是,当我尝试在嵌入在 PHP 文件中的标记中的 JavaScript 代码上设置断点时,我会得到其他人都引用的小断点。当我选择调试项目的选项时,我可以调试 PHP 代码,但从未命中 JavaScript 断点。

The change that I made that finally (for me) caused the JavaScript breakpoints to be hit so I could step through code using the Netbeans debugger was to remove the Javascript from the file containing the PHP/HTML code and place the JavaScript in a separate file that only contained JavaScript via a within the PHP file. Magically, I could debug both JavaScript and PHP within the same debugging session without any extra setup.

我最终(对我而言)所做的更改导致命中 JavaScript 断点,因此我可以使用 Netbeans 调试器单步调试代码,这是从包含 PHP/HTML 代码的文件中删除 Javascript 并将 JavaScript 放在单独的文件中仅通过 PHP 文件中的 a 包含 JavaScript。神奇的是,我可以在同一个调试会话中同时调试 JavaScript 和 PHP,无需任何额外设置。

Of course, one alternative is to use the debugger within the browser, such as Chrome developer tools, but I really wanted to be able to debug everything from within the same Netbeans environment. Works like a charm now.

当然,另一种选择是在浏览器中使用调试器,例如 Chrome 开发人员工具,但我真的希望能够在同一个 Netbeans 环境中调试所有内容。现在就像一个魅力。

回答by Jovo Skorupan

When you end up solving cross browser compatibility you'll have to use particular browser console/debugger implementation (which may not be fancy). Before that enjoy in ChromeDevTools or FireBug :)

当您最终解决跨浏览器兼容性问题时,您将不得不使用特定的浏览器控制台/调试器实现(这可能并不花哨)。在此之前,请使用 ChromeDevTools 或 FireBug :)

回答by Joachim Rohde

Never used the JavaScript debugger myself but you find herea tutorial if it has to be the Netbeans debugger. As an alternative I can recommend the JavaScript debugger from Firebug.

我自己从未使用过 JavaScript 调试器,但如果它必须是 Netbeans 调试器,您可以在此处找到教程。作为替代方案,我可以推荐Firebug的 JavaScript 调试器。

回答by Nick

Use the Chrome debugger once the page is loaded in the browser.

在浏览器中加载页面后,使用 Chrome 调试器。