aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/createprocessinginstruction
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/document/createprocessinginstruction
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/document/createprocessinginstruction')
-rw-r--r--files/zh-cn/web/api/document/createprocessinginstruction/index.html46
1 files changed, 46 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/createprocessinginstruction/index.html b/files/zh-cn/web/api/document/createprocessinginstruction/index.html
new file mode 100644
index 0000000000..7061666c12
--- /dev/null
+++ b/files/zh-cn/web/api/document/createprocessinginstruction/index.html
@@ -0,0 +1,46 @@
+---
+title: Document.createProcessingInstruction()
+slug: Web/API/Document/createProcessingInstruction
+translation_of: Web/API/Document/createProcessingInstruction
+---
+<p id="Summary">{{APIRef("DOM")}}</p>
+
+<p><code>createProcessingInstruction() </code>创建一个新的处理指令节点,并返回。</p>
+
+<h2 id="Syntax" name="Syntax">Syntax</h2>
+
+<pre class="eval"><em>Processing instruction node</em> = document.createProcessingInstruction(target, data)
+</pre>
+
+<h3 id="Parameters" name="Parameters">Parameters</h3>
+
+<ul>
+ <li><code>Processing Instruction node</code> 是 {{ domxref("ProcessingInstruction") }} 节点.</li>
+ <li><code>target</code> 是指处理指令节点的target部分 (i.e., &lt;?<em>target</em> ... ?&gt;</li>
+ <li><code>data</code> 是一个字符串,包含了将要添加到节点内的数据。</li>
+</ul>
+
+<h3 id="Notes" name="Notes">异常</h3>
+
+<dl>
+ <dt><code>NOT_SUPPORTED_ERR</code></dt>
+ <dd>Thrown if you attempt to create a processing instruction node on an HTML document in Gecko 9 {{ geckoRelease("9.0") }} or earlier. In Gecko 10.0 {{ geckoRelease("10.0") }} and later, you can use this method on HTML documents.</dd>
+ <dt><code>DOM_INVALID_CHARACTER</code></dt>
+ <dd>Thrown if you try to add an invalid processing instruction target (it should be an XML name besides any case combination of the letters "xml") or if the closing processing instruction sequence ("?&gt;") is added as part of the data, so unescaped user-provided data cannot be safely used without escaping or otherwise dealing with such situations.</dd>
+</dl>
+
+<h2 id="Example" name="Example">实例</h2>
+
+<pre>var docu = new DOMParser().parseFromString('&lt;xml&gt;&lt;/xml&gt;', "application/xml")
+
+var pi = docu.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');
+
+docu.insertBefore(pi, docu.firstChild);
+
+alert(new XMLSerializer().serializeToString(docu));
+// 弹出框内容: &lt;?xml-stylesheet href="mycss.css" type="text/css"?&gt;&lt;xml/&gt;
+</pre>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createprocessinginstruction">DOM 4: createProcessingInstruction</a></p>