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

2016-02-19 09:21 9 1 收藏

下面这个document.open() 与 document.write()的区别教程由图老师小编精心推荐选出,过程简单易学超容易上手,喜欢就要赶紧get起来哦!

【 tulaoshi.com - Web开发 】

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。

来源:https://www.tulaoshi.com/n/20160219/1590464.html

延伸阅读
标签: Web开发
Cascading Style Sheets: The Definitive Guide, 2nd Edition is a thorough review of all aspects of CSS2.1 and a comprehensive guide to CSS implementation. The book includes new content on positioning, lists and generated content, table layout, user interface, paged media, and more. It explores in detail each individ...
标签: Web开发
Demonstration script that retrieves service data from a computer and  then displays that data in a formatted table in Microsoft Word.  代码如下: Set objWord = CreateObject("Word.Application") objW...
标签: Web开发
Document文档对象是JavaScript中window和frames对象的一个属性,是显示于窗口或框架内的一个文档。描述当前窗口或指定窗口对象的文档。它包含了文档从head到/body的内容。 用法:document (当前窗口) 或 窗口对象.document (指定窗口) 属性: document.title //设置文档标题等价于HTML的title标签 documen...
标签: Web开发
Demonstration script that displays formatted data in a Microsoft Word document.  代码如下: Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Add() Set objSelection...
标签: Web开发
Demonstration script that adds a picture (C:\Scripts\Logo.jog) to  a Microsoft Word document 代码如下: Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Add() Set o...

经验教程

674

收藏

37
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部