diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/document/createcomment | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/document/createcomment')
-rw-r--r-- | files/zh-cn/web/api/document/createcomment/index.html | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/createcomment/index.html b/files/zh-cn/web/api/document/createcomment/index.html new file mode 100644 index 0000000000..1959a87312 --- /dev/null +++ b/files/zh-cn/web/api/document/createcomment/index.html @@ -0,0 +1,33 @@ +--- +title: document.createComment +slug: Web/API/Document/createComment +translation_of: Web/API/Document/createComment +--- +<p>{{ ApiRef() }}</p> +<h3 id="Summary" name="Summary">概述</h3> +<p><code>createComment()</code> 方法用来创建并返回一个注释节点.</p> +<h3 id="Syntax" name="Syntax">语法</h3> +<pre class="eval"><em>var commentNode</em> = document.createComment(data) +</pre> +<h3 id="Parameters" name="Parameters">参数</h3> +<ul> + <li><code>commentNode</code> 是一个注释节点.</li> + <li><code>data</code> 是一个字符串,包含了注释的内容.</li> +</ul> +<h3 id="Example" name="Example">例子</h3> +<pre>var docu = new DOMParser().parseFromString('<xml></xml>', "application/xml") + +var comment = docu.createComment('这是注释内容'); + +docu.getElementsByTagName('xml')[0].appendChild(comment); + +alert(new XMLSerializer().serializeToString(docu)); +// 弹出 <xml><!--这是注释内容--></xml> +</pre> +<h3 id="Notes" name="Notes">备注</h3> +<ul> + <li>如果data字符串包含了 "--" ,则会抛出 <code>NS_ERROR_DOM_INVALID_CHARACTER_ERR</code>异常,这种情况需要对"--" 字符串进行转义.</li> +</ul> +<h3 id="Specification" name="Specification">规范</h3> +<p><a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-createComment">createComment</a></p> +<p>{{ languages( {"en": "en/DOM/document.createComment" } ) }}</p> |