document.open() 与 document.write()的区别
更新时间:2007年08月13日 19:53:13 作者:
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
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。
看一个例子:
<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。
相关文章
JavaScript1.6数组新特性介绍以及JQuery的几个工具方法
这篇文章主要是对JavaScript1.6数组新特性以及JQuery的几个工具方法进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助2013-12-12jquery下onpropertychange事件的绑定方法
用了onchange事件,但是在输入的时候,用Javascript计算出并填值的那一列并不会响应onchange 事件。2010-08-08HTML+CSS+JavaScript做女朋友版的刮刮乐(一看就会)
这篇文章主要介绍了HTML+CSS+JavaScript做女朋友版的刮刮乐(一看就会)本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2021-08-08
最新评论