我想通过代码强制Chrome调试器在一行上中断,或者使用某种注释标记,例如console.break()。


当前回答

设置按钮点击监听器并调用调试器;

例子

$("#myBtn").click(function() {
 debugger;   
});

Demo

http://jsfiddle.net/hBCH5/

JavaScript中调试的资源

http://www.laurencegellert.com/2012/05/the-three-ways-of-setting-breakpoints-in-javascript/ http://berzniz.com/post/78260747646/5-javascript-debugging-tips-youll-start-using-today

其他回答

你可以使用调试器;在你的代码中。如果开发人员控制台是打开的,执行将中断。它也适用于firebug。

在“Scripts”选项卡上,转到代码所在的位置。在行号左侧,单击。这将设置一个断点。

截图:

然后,您将能够在正确的选项卡中跟踪断点(如屏幕截图所示)。

调试JavaScript代码的方法有很多。以下两种方法被广泛用于通过代码调试JavaScript

使用console.log()在浏览器中打印出值 控制台。(这将帮助您理解某些点上的值 你的代码) 调试器的关键字。添加调试器;去你想去的地方 调试,然后打开浏览器的开发人员控制台并导航到 来源选项卡。

有关调试JavaScript代码的更多工具和方法,请参见W3School提供的这个链接。

调试器是EcmaScript保留的关键字,从ES5开始提供可选语义

因此,它不仅可以在Chrome中使用,还可以通过节点调试myscript.js在Firefox和node .js中使用。

标准说:

Syntax DebuggerStatement : debugger ; Semantics Evaluating the DebuggerStatement production may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect. The production DebuggerStatement : debugger ; is evaluated as follows: If an implementation defined debugging facility is available and enabled, then Perform an implementation defined debugging action. Let result be an implementation defined Completion value. Else Let result be (normal, empty, empty). Return result.

ES6没有变化。

这个Git预提交钩子可以从merb项目中删除错误的调试器语句

如果想在提交时删除调试器断点,可能有用