如何将调试代码添加到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()的内容和顺序,它们可以很容易地检查程序的运行状况。