aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/node/normalize
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/node/normalize
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/node/normalize')
-rw-r--r--files/zh-cn/web/api/node/normalize/index.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/node/normalize/index.html b/files/zh-cn/web/api/node/normalize/index.html
new file mode 100644
index 0000000000..ecdd1ac0c0
--- /dev/null
+++ b/files/zh-cn/web/api/node/normalize/index.html
@@ -0,0 +1,73 @@
+---
+title: Node.normalize()
+slug: Web/API/Node/normalize
+tags:
+ - API
+ - Method
+ - Node
+translation_of: Web/API/Node/normalize
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p><code>Node.normalize()</code> 方法将当前节点和它的后代节点”规范化“(normalized)。在一个"规范化"后的DOM树中,不存在一个空的文本节点,或者两个相邻的文本节点。</p>
+
+<p>注1:“空的文本节点”并不包括空白字符(空格,换行等)构成的文本节点。</p>
+
+<p>注2:两个以上相邻文本节点的产生原因包括:</p>
+
+<ol>
+ <li>通过脚本调用有关的DOM接口进行了文本节点的插入和分割等。</li>
+ <li>HTML中超长的文本节点会被浏览器自动分割为多个相邻文本节点。</li>
+</ol>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox"><em>element</em>.normalize();
+</pre>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<pre class="brush:js">var wrapper = document.createElement("div");
+
+wrapper.appendChild(document.createTextNode("Part 1 "));
+wrapper.appendChild(document.createTextNode("Part 2 "));
+
+// 这时(规范化之前),wrapper.childNodes.length === 2
+// wrapper.childNodes[0].textContent === "Part 1 "
+// wrapper.childNodes[1].textContent === "Part 2 "
+
+wrapper.normalize();
+// 现在(规范化之后), wrapper.childNodes.length === 1
+// wrapper.childNodes[0].textContent === "Part 1 Part 2"
+</pre>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("DOM WHATWG", "#dom-node-normalize", "Node: normalize")}}</td>
+ <td>{{Spec2("DOM WHATWG")}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.Node.normalize")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("Text.splitText()")}}</li>
+</ul>