简体   繁体   English

在单页应用程序中调试JavaScript

[英]Debugging javascript in a single page application

In a single page application, I load a different html page with jquery. 在单页应用程序中,我使用jquery加载了另一个HTML页面。

$('#lodger').click(function () {
    $('#main').load('lodger.html');
});

In my page lodger.html, I have some javascript directly in the page. 在我的页面lodger.html中,我直接在页面中有一些javascript。

Is there a way to debug it? 有没有一种调试方法? I haven't found a way to do it with Chrome 我还没有找到使用Chrome浏览器的方法

The chrome website explains how to debug pretty well: chrome网站说明了如何很好地调试:

https://developer.chrome.com/devtools/docs/javascript-debugging https://developer.chrome.com/devtools/docs/javascript-debugging

在此处输入图片说明

I would refrain from using debugger; 我将避免使用debugger; . Sooner or later you're going to accidentally leave this bit of code in your script and it'll start pausing your website for users who have dev tools open. 迟早您会不小心将这段代码留在脚本中,并且它将开始为已打开开发工具的用户暂停您的网站。 Can be very embarrassing. 可能会很尴尬。

You can use debugger; 您可以使用debugger; notation inside your inline code, and, having DevTools opened these breakpoints will automatically be hit: 内联代码中的符号,打开DevTools会自动打断这些断点:

$('#lodger').click(function () {
    debugger;
    $('#main').load('lodger.html');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM