如何向 JavaScript 添加调试代码?
htmljavascriptprogramming scripts
要向 JavaScript 添加调试代码,请在程序中使用 alert() 或 document.write() 方法。例如,
var tuning = true; var whichImage = "widget"; if( tuning ) alert( "Calls swapImage() withargument: " + whichImage ); var swapStatus = swapImage( whichImage ); if( tuning ) alert( "Exits swapImage() with swapStatus=" + swapStatus );
检查 alert() 出现的内容和顺序,您可以非常轻松地检查程序的运行状况。