JavaScript中document.open()方法的使用指南

作者:竹影时间:2026-10-27 15:16:57浏览:430

本文介绍JavaScript中document.open()方法的使用。该方法用于打开新文档,配合document.write()写入内容,最后通过document.close()关闭并显示。文章提供了完整的代码示例,展示如何在页面加载时动态生成文本内容。

document.open()方法概述

document.open()方法用于打开一个新的文档流,随后可以使用document.write()方法向该文档写入内容,最后调用document.close()方法关闭文档操作,从而使写入的内容在页面上显示出来。



具体使用示例如下:


代码实现如下:

 
代码示例<script type="text/javascript">
window.onload=hello;
function hello(){
var msg = "JavaScript真好玩!";
document.open();
document.write(msg);
document.close();
} 
</script>
作者最新文章