首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

关于document.close(),该如何解决

2012-04-05 
关于document.close()都说如果用了document.write(),就一定要用close()函数,否则不会输出结果。可是我自己

关于document.close()
都说如果用了document.write(),就一定要用close()函数,否则不会输出结果。
可是我自己试验了,不用close也能正常输出啊?
到底close要不要用,什么情况下必须使用?

我的代码:

<head>
<title> Insert   title   here </title>
<script   type= "text/javascript ">
function   output(){
document.write( " <B> HelloWorld! </B> ");
}
</script>
</head>
<body>

<input   type= "button "   value= "O "   id= "btnOpen "   name= "btnOpen "   onclick= "output() ">

</body>

[解决办法]
You should not use the write or writeln methods on the current document after the document has finished loading unless you first call the open method, which clears the current document 's window and erases all variables.

Note When document.write or document.writeln is used in an event handler, document.close should also be used.

热点排行