代码示例:(标识:jsck_doc_write_1)
<!DOCTYPE html>
<html>
<body>

<h1>Document 对象</h1>

<h2>open() 方法</h2>

<p>如果在关闭的文档上使用 document.write(),则会自动调用 document.open()。</p>

<p>这将删除现有的内容。</p>

<button onclick="myFunction()">试一试</button>

<script>
function myFunction() {
  document.write("<h1>Hello World</h1>");
}
</script>

</body>
</html>
运行结果: