我在看书的时候看到这样一段:<HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
function singOut() {
var theMoment = new Date();
var theHour = theMoment.getHours();
var theMinute = theMoment.getMinutes();
var theDisplacement = (theMoment.getTimezoneOffset() / 60);
theHour -= theDisplacement;
if (theHour > 23) {
theHour -= 24
}
document.write(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
window.setTimeout("singOut();", 60000);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
singOut();
</SCRIPT>
</BODY>
</HTML>它说“该示例显示了一个每隔一分钟就显示时间的脚本,但是在第一次显示后由于它从过程中将自己清除,因此会导致失败。”并且他还说“如果使用 window 对象的 alert() 方法而不是 document.write(),则该脚本可以运行。”
我想知道write和alert是如何解析文本的。
<HEAD>
<SCRIPT LANGUAGE="JScript">
function singOut() {
var theMoment = new Date();
var theHour = theMoment.getHours();
var theMinute = theMoment.getMinutes();
var theDisplacement = (theMoment.getTimezoneOffset() / 60);
theHour -= theDisplacement;
if (theHour > 23) {
theHour -= 24
}
document.write(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
window.setTimeout("singOut();", 60000);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
singOut();
</SCRIPT>
</BODY>
</HTML>它说“该示例显示了一个每隔一分钟就显示时间的脚本,但是在第一次显示后由于它从过程中将自己清除,因此会导致失败。”并且他还说“如果使用 window 对象的 alert() 方法而不是 document.write(),则该脚本可以运行。”
我想知道write和alert是如何解析文本的。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货