aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/createcdatasection
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/createcdatasection
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/createcdatasection')
-rw-r--r--files/zh-cn/web/api/document/createcdatasection/index.html67
1 files changed, 67 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/createcdatasection/index.html b/files/zh-cn/web/api/document/createcdatasection/index.html
new file mode 100644
index 0000000000..298e0021fb
--- /dev/null
+++ b/files/zh-cn/web/api/document/createcdatasection/index.html
@@ -0,0 +1,67 @@
+---
+title: Document.createCDATASection()
+slug: Web/API/Document/createCDATASection
+tags:
+ - API
+ - DOM
+ - 参考
+ - 方法
+translation_of: Web/API/Document/createCDATASection
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p><strong><code>createCDATASection()</code></strong> 创建并返回一个新的 CDATA 片段节点。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">var <var>CDATASectionNode</var> = <var>document</var>.createCDATASection(<var>data</var>);
+</pre>
+
+<ul>
+ <li><var>CDATASectionNode</var> 是一个 <a href="/en-US/docs/Web/API/CDATASection">CDATA 片段</a>节点。</li>
+ <li><var>data</var> 包含了要被添加至 CDATA 片段的数据的字符串。</li>
+</ul>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush:js">var docu = new DOMParser().parseFromString('&lt;xml&gt;&lt;/xml&gt;', 'application/xml');
+
+var cdata = docu.createCDATASection('Some &lt;CDATA&gt; data &amp; then some');
+
+docu.getElementsByTagName('xml')[0].appendChild(cdata);
+
+alert(new XMLSerializer().serializeToString(docu));
+// Displays: &lt;xml&gt;&lt;![CDATA[Some &lt;CDATA&gt; data &amp; then some]]&gt;&lt;/xml&gt;
+</pre>
+
+<h2 id="备注">备注</h2>
+
+<ul>
+ <li>This will only work with XML, not HTML documents (as HTML documents do not support CDATA sections); attempting it on an HTML document will throw <code>NOT_SUPPORTED_ERR</code>.</li>
+ <li>Will throw a <code>NS_ERROR_DOM_INVALID_CHARACTER_ERR</code> exception if one tries to submit the closing CDATA sequence ("<code>]]&gt;</code>") as part of the data, so unescaped user-provided data cannot be safely used without with this method getting this exception ({{domxref("document.createTextNode","createTextNode()")}} can often be used in its place).</li>
+</ul>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('DOM WHATWG', '#dom-document-createcdatasection', 'document.createCDATASection')}}</td>
+ <td>{{Spec2('DOM WHATWG')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Document.createCDATASection")}}</p>