初学JavaScript,想实现执行JavaScript代码过程中,同时在网页中输出中间过程的值??如何能做到?
因为JavaScript好象没有VB那样的F8可以逐句执行再监视变量的每一条语句的运行值,我就想在中间利用this.document.writeln对象写到网页上去,结果不行?请问如果能实现这样的"监视""效果?
具体代码如下:
<body bgcolor="#fef4d9" OnLoad="stack()">
<SCRIPT LANGUAGE="JavaScript">
<!-- hide script from old browsers 精彩javascript特效!!!
var phrase = "精彩javascript特效!!!;
var lenPhrase = phrase.length;
var phraseOut = "";
var pause = 25;
var i=0;
var j=0;
var animateWidth = 20;
var position=animateWidth;
function stack() {
if (phrase.charAt(i) != " ") {
phraseOut = "";
for (j=0; j<i; j++) { phraseOut += phrase.charAt(j); }
for (j=i; j<position; j++) { phraseOut += " "; }
phraseOut += phrase.charAt(i);
this.document.writeln("<center><p><B>"+ phraseOut +"</B></p></center>");
alert("当前"phraseOut的值是;"+phraseOut); 想加这2句结果程序不能正常执行,好象执行到这里就不再往下运行了,错误是提示是第1行,缺少对象,
for (j=position; j<animateWidth; j++) { phraseOut += " "; }
window.status = phraseOut;
if (position == i) { animateWidth++; position = animateWidth; i++; }
else { position--; }
}
else { i++ }
if (i<lenPhrase) {setTimeout("stack()",pause);}
}
// end hiding contents -->
</SCRIPT>
</body>