请问在JavaScript里面document.open()和document.close()的作用

来源:百度知道 编辑:UC知道 时间:2024/05/24 19:27:44
要使用document.write()是不是一定要用到open()和close()呢?请用自己的话里解释,不要抄那些长编大论的文章来,最好用一些简单的实例说明,本人先感谢各位!

只有在当前窗口向自己弹出窗口中写东西时才使用 document.open() 与 document.close(), 看实例

<script language="javascript">
var newWindow = window.open('about:blank');

newWindow.document.open(); // 打开弹出窗口的输入流
newWindow.document.write("hello"); // 向打开的窗口中写数据
newWindow.document.write(" world");
newWindow.document.close(); // 关闭弹出窗口的输入流
</script>

不需要啊,document.write()就可以直接输出字符串了,不需要open和close,document也没有open和close这两个方法。