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.覆盖是发生在页面加载结束之后 <html> <head> <title> Insert title here </title> <script type= "text/javascript "> function output(){ document.writeln("aaaaaaaaaaa"); document.close(); document.writeln("xxxxxxxxxxx"); } </script> </head> <body> <input type= "button" value="test write" onclick= "output()"/> </body> </html>
<html>
<head>
<title> Insert title here </title>
<script type= "text/javascript ">
function output(){
document.writeln("aaaaaaaaaaa");
document.close();
document.writeln("xxxxxxxxxxx");
}
</script>
</head>
<body>
<input type= "button" value="test write" onclick= "output()"/>
</body>
</html>
另附上window.close()与document.close()的区别
http://hi.baidu.com/fangkaiming/blog/item/0a724097727b6c6e55fb968c.html
可定是输出
xxxxxxxxx
aaaaaaaaaa
不是矛盾吗???????????????
而装载完以后document.close()会关闭输入流,如果再次执行
write会重新清空页面开启输入流。你用firebug设置断点的话可以很明显
的看到页面的变化,若注释掉先输出a____ 然后b____
document.open();//这个方法好像可有可无
document.writeln("a___");
//document.close();
document.writeln("b___");
document.close();
若不注释掉输出a____ b____
此外若最后一个close被注释掉则可以但到虽然也输出a____ b____
但可以看到页面一直没有加载完毕说明他还在等待输入