document.open() 与 document.write()

2019-12-27,,,

document.open()  打开一个新的空白文档,在IE下,open有两个默认参数,相当于document.open("text/html",'""),第二个参数只有一个值可选:replace,如果启用了该值,则新建的文档会覆盖当前页面的文档(相当于清空了原文档里的所有元素,且不能后退即,浏览器的后退按钮不可用);
看一个例子:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
平常都不写document.open()  document.close(),因为浏览器会在write之前先open一个文档,再把write的内容输出到原文档里面。write结束后,默认是不会有close的,否则第二行document.write的时候就会覆盖之前的write。

您可能感兴趣的文章:

  • js中document.write使用过程中的一点疑问解答
  • js document.write()使用介绍
  • document.write()及其输出内容的样式、位置控制
  • document.write与writeln的输出内容区别说明
  • 在网页中使用document.write时遭遇的奇怪问题
  • 第一个JavaScript入门基础 document.write输出
  • document.open() 与 document.write()的区别
  • 代码生成器 document.write()
  • JS 中document.write()的用法和清空的原因浅析

《document.open() 与 document.write().doc》

下载本文的Word格式文档,以方便收藏与打印。