From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../createprocessinginstruction/index.html | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 files/zh-cn/web/api/document/createprocessinginstruction/index.html (limited to 'files/zh-cn/web/api/document/createprocessinginstruction') 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 +--- +

{{APIRef("DOM")}}

+ +

createProcessingInstruction() 创建一个新的处理指令节点,并返回。

+ +

Syntax

+ +
Processing instruction node = document.createProcessingInstruction(target, data)
+
+ +

Parameters

+ + + +

异常

+ +
+
NOT_SUPPORTED_ERR
+
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.
+
DOM_INVALID_CHARACTER
+
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 ("?>") is added as part of the data, so unescaped user-provided data cannot be safely used without escaping or otherwise dealing with such situations.
+
+ +

实例

+ +
var docu = new DOMParser().parseFromString('<xml></xml>',  "application/xml")
+
+var pi = docu.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');
+
+docu.insertBefore(pi, docu.firstChild);
+
+alert(new XMLSerializer().serializeToString(docu));
+// 弹出框内容: <?xml-stylesheet href="mycss.css" type="text/css"?><xml/>
+
+ +

规范

+ +

DOM 4: createProcessingInstruction

-- cgit v1.2.3-54-g00ecf