diff options
author | MDN <actions@users.noreply.github.com> | 2021-03-24 00:27:57 +0000 |
---|---|---|
committer | MDN <actions@users.noreply.github.com> | 2021-03-24 00:27:57 +0000 |
commit | 8d7ad7715e19a445def22de6d5f3d9519cebe69e (patch) | |
tree | dfeab89fe885baadfaa3629850e4dbf53a9a8669 /files/zh-cn/conflicting/web/api/element/namespaceuri | |
parent | 0511ab6f682be0c8401377e50cd4a164e87ec589 (diff) | |
download | translated-content-8d7ad7715e19a445def22de6d5f3d9519cebe69e.tar.gz translated-content-8d7ad7715e19a445def22de6d5f3d9519cebe69e.tar.bz2 translated-content-8d7ad7715e19a445def22de6d5f3d9519cebe69e.zip |
[CRON] sync translated content
Diffstat (limited to 'files/zh-cn/conflicting/web/api/element/namespaceuri')
-rw-r--r-- | files/zh-cn/conflicting/web/api/element/namespaceuri/index.html | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/files/zh-cn/conflicting/web/api/element/namespaceuri/index.html b/files/zh-cn/conflicting/web/api/element/namespaceuri/index.html new file mode 100644 index 0000000000..b2f0fa1e38 --- /dev/null +++ b/files/zh-cn/conflicting/web/api/element/namespaceuri/index.html @@ -0,0 +1,139 @@ +--- +title: Node.namespaceURI +slug: conflicting/Web/API/Element/namespaceURI +translation_of: Web/API/Node/namespaceURI +original_slug: Web/API/Node/namespaceURI +--- +<div>{{APIRef("DOM")}}{{obsolete_header}}</div> + +<p><code><strong>Node.namespaceURI</strong></code> 是一个只读属性,返回节点的命名空间URI(namespace URI),如果节点不在一个命名空间中,则返回 <code>null</code>。当节点是文档节点时,返回当前文档的 XML 命名空间(namespace)。</p> + +<div class="warning"> +<p>在 DOM4 中, 此接口从<code>Node</code> 被移入 {{domxref("Element")}} 和 {{domxref("Attr")}}接口.</p> +</div> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>namespace</em> = <em>node</em>.namespaceURI</pre> + +<h2 id="Example" name="Example">示例</h2> + +<p>在这个示例中, 使用 <a href="/en-US/docs/DOM/Node.localName" title="DOM/Node.localName">localName</a> 和 <code>namespaceURI来检查这个node</code>. 如果 <code>namespaceURI</code> 返回 XUL 命名空间并且 <code>localName</code> 返回 "browser", 说明这个节点属于 XUL <code><browser/></code>.</p> + +<pre class="brush:js">if (node.localName == "browser" && + node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") { + // this is a XUL browser +}</pre> + +<h2 id="Notes" name="Notes">备注</h2> + +<p>这不是一个计算值,它是基于检查范围内的命名空间声明的名称空间查找的结果。节点的命名空间URI在节点创建时被固定。</p> + +<p>在Firefox 3.5或更早的版本中,HTML文档中HTML元素的名称空间URI是<code>null</code>。在之后的版本中,由<code><a class="external" href="http://www.w3.org/1999/xhtml" rel="freelink">http://www.w3.org/1999/xhtml</a></code> 作为XHTML,符合HTML5. {{gecko_minversion_inline("1.9.2")}}</p> + +<p>除了<code>ELEMENT_NODE</code> a和 <code>ATTRIBUTE_NODE</code> 以外的 <a href="/en-US/docs/DOM/Node.nodeType" title="DOM/Node/NodeType/Node.nodeType">nodeType</a> 中 node 的 <code>namespaceURI</code> 永远是<code>null</code>.</p> + +<p>你可以使用DOM2的方法 <a href="/en-US/docs/DOM/document.createElementNS" title="DOM/document.createElementNS">document.createElementNS</a> 来创建一个有特殊 <code>namespaceURI</code> 的元素.</p> + +<p>在<a class="external" href="http://www.w3.org/TR/xml-names11/">XML的命名空间</a>中,属性不会从它附加到的元素继承它的命名空间。如果属性未显式地给出命名空间,则它没有命名空间.</p> + +<p>DOM本身不处理或执行命名空间验证, 因此应该有由DOM应用程序进行必要的验证。请注意,命名空间前缀一旦与特定节点关联,则不能更改.</p> + +<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("DOM3 Core", "core.html#ID-NodeNSname", "Node.namespaceURI")}}</td> + <td>{{Spec2("DOM3 Core")}}</td> + <td>当设置为 <code>null</code> 是指定动作.</td> + </tr> + <tr> + <td>{{SpecName("DOM2 Core", "core.html#Namespaces-Considerations", "DOM Level 2 Core: XML Namespaces")}}</td> + <td>{{Spec2("DOM2 Core")}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("DOM2 Core", "core.html#ID-NodeNSname", "Node.namespaceURI")}}</td> + <td>{{Spec2("DOM2 Core")}}</td> + <td>初始化</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>特征</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>是否支持</td> + <td>{{CompatVersionUnknown}}<br> + {{CompatNo}}46.0<sup>[1]</sup></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[2]</sup><br> + {{CompatNo}} {{CompatGeckoDesktop("48.0")}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>特征</th> + <th>Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>是否支持</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[2]</sup><br> + {{CompatNo}} {{CompatGeckoMobile("48.0")}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] 从DOM4标准开始, 此接口被移入{{domxref("Element")}} 和 {{domxref("Attr")}} 接口.</p> + +<p>[2] 在 Gecko 5.0 之前 {{geckoRelease("5.0")}}, 这是一个读写属性; 从 Gecko 5.0 起,这是一个只读属性, 符合标准.</p> + +<h2 id="参考">参考</h2> + +<ul> + <li>{{domxref("Node.localName")}}</li> + <li>{{domxref("Node.prefix")}}</li> + <li>{{domxref("Element.namespaceURI")}}</li> + <li>{{domxref("Attr.namespaceURI")}}</li> +</ul> |