aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/node/contains/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/node/contains/index.html')
-rw-r--r--files/zh-cn/web/api/node/contains/index.html96
1 files changed, 96 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/node/contains/index.html b/files/zh-cn/web/api/node/contains/index.html
new file mode 100644
index 0000000000..4f54315c26
--- /dev/null
+++ b/files/zh-cn/web/api/node/contains/index.html
@@ -0,0 +1,96 @@
+---
+title: Node.contains
+slug: Web/API/Node/contains
+translation_of: Web/API/Node/contains
+---
+<div>{{ApiRef}}</div>
+
+<h2 id="Summary" name="Summary">概述</h2>
+
+<p><strong>Node.contains()</strong>返回的是一个布尔值,来表示传入的节点是否为该节点的后代节点。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox">node.contains( otherNode )
+</pre>
+
+<ul>
+ <li><code>node</code> 是否包含otherNode节点.</li>
+ <li><code>otherNode</code> 是否是node的后代节点.</li>
+</ul>
+
+<p>如果 <code>otherNode</code> 是 <code>node 的后代节点或是</code> <code>node</code> 节点本身.则返回<code>true</code> , 否则返回 <code>false</code>.</p>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<p>下面的函数用来检查一个元素是否是body元素的后代元素且非body元素本身.</p>
+
+<pre class="brush:js">function isInPage(node) {
+ return (node === document.body) ? false : document.body.contains(node);
+}</pre>
+
+<ul>
+ <li><code>node</code> 是我们想要检查的元素节点.</li>
+</ul>
+
+<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("9.0")}}</td>
+ <td>5.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>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile("9.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<ul>
+ <li><a class="external" href="http://www.w3.org/TR/domcore/#dom-node-contains" title="http://www.w3.org/TR/domcore/#dom-node-contains">DOM Level 4: contains</a></li>
+</ul>
+
+<h2 id="See_also" name="See_also">相关链接</h2>
+
+<ul>
+ <li>{{domxref("Node.hasChildNodes")}}</li>
+</ul>