How to set a JavaScript breakpoint from code in Chrome?

我想强制Chrome调试器通过代码断行,或者使用某种类型的评论标记,如console.break()


You can use debugger; within your code. If the developer console is open, execution will break. It works in firebug as well.


Set up a button click listener and call the debugger;

Example

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

Demo

http://jsfiddle.net/hBCH5/

Resources on debugging in 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

  • As other have already said, debugger; is the way to go. I wrote a small script that you can use from the command line in a browser to set and remove breakpoint right before function call: http://andrijac.github.io/blog/2014/01/31/javascript-breakpoint/

    链接地址: http://www.djcxy.com/p/17336.html

    上一篇: jQuery ajax回调在Firefox中表现得很奇怪

    下一篇: 如何在Chrome中通过代码设置JavaScript断点?