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

dream梦_9

dream梦_9

2016-02-19 09:21

下面这个document.open() 与 document.write()的区别教程由图老师小编精心推荐选出,过程简单易学超容易上手,喜欢就要赶紧get起来哦!
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。
展开更多 50%)
分享

猜你喜欢

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

Web开发
document.open() 与 document.write()的区别

Open and Print a Word Document

Web开发
Open and Print a Word Document

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

jquery $(document).ready() 与window.onload的区别

Web开发
jquery $(document).ready() 与window.onload的区别

XSLT document()函数在IE与Firefox中的区别

Web开发
XSLT document()函数在IE与Firefox中的区别

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

jquery中的$(document).ready()与window.onload的区别

Web开发
jquery中的$(document).ready()与window.onload的区别

document.all与WEB标准

Web开发
document.all与WEB标准

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

牛顿迭代法求多项式在1.5附近的值2*x的3次幂--4x平方+3*x-6=0的实现代码

牛顿迭代法求多项式在1.5附近的值2*x的3次幂--4x平方+3*x-6=0的实现代码

mysql 编码设置命令

mysql 编码设置命令
下拉加载更多内容 ↓