Javascript中理解Document.write()示例

 
  1. 在调用 write( ) 方法时,如果该文档不处于在调用 write( ) 方法时的打开和分析的过程中,该方法将打开并清除该文档,所以它可能是有危险的。该示例显示了一个每隔一分钟就显示时间的脚本,但是在第一次显示后由于它从过程中将自己清除,因此会导致失败。 
  2. <HTML>
  3. <HEAD>
  4. <SCRIPT LANGUAGE="JScript">
  5. function singOut()  {
  6. var theMoment = new Date();
  7. var theHour = theMoment.getHours();
  8. var theMinute = theMoment.getMinutes();
  9. var theDisplacement = (theMoment.getTimezoneOffset() / 60);
  10. theHour -= theDisplacement;
  11. if (theHour > 23)  {
  12. theHour -= 24
  13. }
  14. document.write(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
  15. window.setTimeout("singOut();", 60000);
  16. }
  17. </SCRIPT>
  18. </HEAD>
  19. <BODY>
  20. <SCRIPT>
  21. singOut();
  22. </SCRIPT>
  23. </BODY>
  24. </HTML>
  25. 如果使用 window 对象的 alert() 方法而不是 document.write(),则该脚本可以运行。 
  26. window.alert(theHour + " hours, " + theMinute + " minutes, Coordinated Universal Time.");
  27. window.setTimeout("singOut();", 60000);
  28. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值