我该如何在我的 JavaScript 中添加调试代码?
要在 JavaScript 中添加调试代码,请在程序中使用 alert() 或 document.write() 方法。例如:
var debugging = true; var whichImage = "widget"; if( debugging ) alert( "Calls swapImage() with argument: " + whichImage ); var swapStatus = swapImage( whichImage ); if( debugging ) alert( "Exits swapImage() with swapStatus=" + swapStatus );
检查 alert()的内容和出现顺序,你可以非常容易地检查程序的健康状况。
广告