小白教程
所有教程
关于
Search
172.69.58.33
172.69.58.33
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Met doc open”的源代码
本页内容
上一节:
Met_document_normalizedocument
下一节:
Met_document_queryselector
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:document.open()}}[[Category:dom obj document|33]] = HTML DOM open() 方法 = [[dom obj document|Document 对象]] == 定义和用法 == open() 方法打开一个输出流来收集 [[met doc write|document.write()]] 或 [[met doc writeln|document.writeln()]] 方法输出的内容。 调用 open() 方法打开一个新文档并且用 write() 方法设置文档内容后,必须记住用 [[met doc close|document.close()]] 方法关闭文档,并迫使其内容显示出来。 '''注意:'''如果目标文件已经存在,它将被清除。如果这个方法没有参数,会显示一个新窗口(about:blank)。 == 语法 == <pre> document.open(MIMEtype,replace)</pre> {| class="table table-striped table-hover" ! 参数 ! 描述 |- | MIMEtype | 可选。规定正在写的文档的类型。默认值是 "text/html"。 |- | replace | 可选。当此参数设置后,可引起新文档从父文档继承历史条目。 |} == 浏览器支持 == 所有主要浏览器都支持 open() 方法 打开一个输出流并添加文本,然后关闭输出流: <sample title="" desc="" lang="html" hererun="1"> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script> function createDoc(){ var doc=document.open("text/html","replace"); var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>"; doc.write(txt); doc.close(); } </script> </head> <body> <input type="button" value="新文档" onclick="createDoc()"> </body> </html> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script> function createDoc(){ var doc=document.open("text/html","replace"); var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>"; doc.write(txt); doc.close(); } </script> </head> <body> <input type="button" value="新文档" onclick="createDoc()"> </body> </html> </run> == 实例 2 == 打开一个输出流 (一个新窗口; about:blank),并添加文本,然后关闭输出流: <sample title="" desc="" lang="html" hererun="1"> <html> <body> <script> var w=window.open(); w.document.open(); w.document.write("<h1>Hello World!</h1>"); w.document.close(); </script> </body> </html> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script> function createDoc(){ var w=window.open(); w.document.open(); w.document.write("<h1>Hello World!</h1>"); w.document.close(); } </script> </head> <body> <input type="button" value="新窗口的新文档" onclick="createDoc()"> </body> </html> </run> [[dom obj document|Document 对象]]
返回至“
Met doc open
”。
上一节:
Met_document_normalizedocument
下一节:
Met_document_queryselector