document.write()将文本字符串写入由 document.open() 打开的文档流.因为 document.write() 会向文档流中写入内容所以在已关闭已加载的文档上调用 document.write() 会自动调用 document.open()这将清空文档。在未调用 document.open() 的情况下向已加载的文档写入内容将自动调用 document.open()。写入后调用 document.close() 告诉浏览器完成页面加载。如果 document.write() 方法 调用嵌入了行级 HTMLscript标签则不会调用 document.open()。注​document.write() 和document.writeln 在 XHTML 文档中无法正常工作你会在控制台收到“Operation is not supported”NS_ERROR_DOM_NOT_SUPPORTED_ERR的错误。当以 .xhtml 文件扩展名打开本地文件或任何使用 application/xhtmlxml MIME 类型的文档时就会出现这种情况。在延迟或异步脚本中使用 document.write() 将被忽略并且你会在错误控制台中收到类似于“A call to document.write() from an asynchronously-loaded external script was ignored”的消息。仅在 Edge 中在 iframe 中多次调用 document.write() 会导致错误“SCRIPT70: Permission denied”兼容性