aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/domimplementation/createdocument/index.html
blob: 59ccafd85342489d785ed675fdda7130587bb5be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: DOMImplementation.createDocument()
slug: Web/API/DOMImplementation/createDocument
translation_of: Web/API/DOMImplementation/createDocument
---
<p>{{ApiRef("DOM")}}</p>

<p><strong><code>DOMImplementation.createDocument()</code>方法创建并返回一个</strong> {{domxref("XMLDocument")}}对象.</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>doc</em> = document.implementation.createDocument(<em>namespaceURI</em>, <em>qualifiedNameStr</em>, <em>documentType</em>);</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><em>namespaceURI</em></dt>
 <dd>被创建的{{domxref("DOMString")}} 文档的namespace URI 是namespace URI ,如果文档不属于任何namespace URI 就为<code>null</code>.</dd>
</dl>

<dl>
 <dt><em>qualifiedNameStr </em></dt>
 <dd> {{domxref("DOMString")}} 是否包含要创建文档的限定名称,即可选的前缀和冒号,以及本地的根元素。</dd>
</dl>

<dl>
 <dt><em>documentType </em>{{optional_inline}}</dt>
 <dd>文档的 <code><a class="internal" href="/En/DOM/DocumentType" title="En/DOM/DocumentType">DocumentType</a> </code>默认为null.</dd>
</dl>

<ul>
</ul>

<h2 id="例子">例子</h2>

<pre class="brush: js">var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
body.setAttribute('id', 'abc');
doc.documentElement.appendChild(body);
alert(doc.getElementById('abc')); // [object HTMLBodyElement]
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-domimplementation-createdocument', 'DOMImplementation.createDocument')}}</td>
   <td>{{Spec2('DOM WHATWG')}}[现时标准]</td>
   <td>
    <p><code>createDocument()</code> 的返回类型从 {{domxref("Document")}} 修改为{{domxref("XMLDocument")}}.<br>
     <code>createDocument()</code>的第三个参数,文档类型,现在是可选的,默认为<code>null</code>.</p>
   </td>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}}</td>
   <td>{{Spec2('DOM3 Core')}}[过时]</td>
   <td>{{SpecName("DOM2 Core")}}无改变</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}}</td>
   <td>{{Spec2('DOM2 Core')}}[过时]</td>
   <td>初始定义.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>

<div class="hidden">本页的兼容性表由结构化数据生成.如果你想对数据做出贡献,请查看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并发送给我们一个拉取请求.</div>

<p>{{Compat("api.DOMImplementation.createDocument")}}</p>

<h2 id="另请参见">另请参见</h2>

<ul>
 <li>归属它的 {{domxref("DOMImplementation")}} 接口.</li>
</ul>