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/node/isequalnode | |
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/node/isequalnode')
-rw-r--r-- | files/zh-cn/web/api/node/isequalnode/index.html | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/node/isequalnode/index.html b/files/zh-cn/web/api/node/isequalnode/index.html new file mode 100644 index 0000000000..c2127a8aed --- /dev/null +++ b/files/zh-cn/web/api/node/isequalnode/index.html @@ -0,0 +1,124 @@ +--- +title: Node.isEqualNode +slug: Web/API/Node/isEqualNode +tags: + - API + - DOM + - Node + - 参考 + - 方法 + - 节点 +translation_of: Web/API/Node/isEqualNode +--- +<div>{{ ApiRef("DOM") }}</div> + +<p> <code><strong>Node.isEqualNode() </strong></code>方法可以判断两个节点是否相等。当两个节点的类型相同,定义特征(defining characteristics)相同(对元素来说,即 id,孩子节点的数量等等),属性一致等,这两个节点就是相等的。一些具体的数据指出:多数时候的比较是根据节点的类型来的。</p> + +<h3 id="语法">语法</h3> + +<pre class="syntaxbox">var <em>isEqualNode</em> = <em>node</em>.isEqualNode(<var>otherNode</var>); +</pre> + +<ul> + <li><font face="Consolas, Liberation Mono, Courier, monospace">otherNode: </font>比较是否相等的节点.</li> +</ul> + +<h2 id="示例">示例</h2> + +<p>在本例中,我们创建了三个 {{HTMLElement("div")}} 块。第一个和第三个 div 都拥有相同的内容和属性,第二个则不一样。然后我们运行 JavaScript ,使用 <code>isEqualNode()</code> 来比较这几个节点。</p> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><div>This is the first element.</div> +<div>This is the second element.</div> +<div>This is the first element.</div> + +<p id="output"></p></pre> + +<h3 id="JavaScript">JavaScript</h3> + +<pre class="brush: js">let output = document.getElementById("output"); +let divList = document.getElementsByTagName("div"); + +output.innerHTML += "div 0 equals div 0: " + divList[0].isEqualNode(divList[0]) + "<br/>"; +output.innerHTML += "div 0 equals div 1: " + divList[0].isEqualNode(divList[1]) + "<br/>"; +output.innerHTML += "div 0 equals div 2: " + divList[0].isEqualNode(divList[2]) + "<br/>";</pre> + +<h3 id="结果">结果</h3> + +<p>{{ EmbedLiveSample('示例', 480) }}</p> + +<h3 id="规范">规范</h3> + +<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-isequalnode', 'Node.isEqualNode')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器支持">浏览器支持</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("1.9")}}</td> + <td>9.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{domxref("Node.isSameNode()")}}</li> +</ul> |