当前位置: 首页 > 图文教程 > 网络编程 > Javascript > document.open() 与 document.write()的区别

Javascript
可实现多表单提交的javascript函数
比较详细的关于javascript中void(0)的具体含义解释
随机显示经典句子或诗歌的javascript脚本
javascript实现的多条新闻公告系统
解析arp病毒背后利用的Javascript技术附解密方法
比较详细的javascript对象的property和prototype是什么一种关系
访问百度和谷歌网速测试的javascript代码
javascript 动态改变层的Z-INDEX的代码style.zIndex
javascript+css实现单击颜色褪去效果
javascript 表单日期选择效果
比较简单的javascript实现input双击后可以编辑
javascript实现的颜色块滑动的动态效果
js实现网页检测是否安装了 Flash Player 插件
javascript 实现父窗口引用弹出窗口的值的脚本
javascript 实现双击才能打开链接的方法
用javascript实现兼容IE7的类库 IE7_0_9.zip提供下载
document.createElement("A")比较不错的属性
用javascript实现不按Ctrl实现Multiple Select多选
JavaScript-世界上误解最深的语言分析
IE和Mozilla的兼容性汇总event

Javascript 中的 document.open() 与 document.write()的区别


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 40 ::
收藏到网摘: n/a

document.open() 打开一个新的空白文档,在IE下,open有两个默认参数,相当于document.open("text/html",'""),第二个参数只有一个值可选:replace,如果启用了该值,则新建的文档会覆盖当前页面的文档(相当于清空了原文档里的所有元素,且不能后退即,浏览器的后退按钮不可用);
看一个例子:
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
document.open("text/html","replace");
document.writeln(Math.random());
document.write("<input type='button' value='back(第二个按钮)' onclick='history.back()'>")
document.close();
document.open("text/html","");
document.writeln(Math.random());
document.write("<input type='button' value='back(第三个按钮)' onclick='history.back()'>")
document.close();
document.open("text/html","");
document.writeln(Math.random());
document.write("<input type='button' value='back(第四个按钮)' onclick='history.back()'>")
document.close();
}
//-->
</SCRIPT>
<input type="button" value="第一个按钮" onclick="test()">
平常都不写document.open() 与 document.close(),因为浏览器会在write之前先open一个文档,再把write的内容输出到原文档里面。write结束后,默认是不会有close的,否则第二行document.write的时候就会覆盖之前的write。