From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/element/namespaceuri/index.html | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 files/zh-cn/web/api/element/namespaceuri/index.html (limited to 'files/zh-cn/web/api/element/namespaceuri') diff --git a/files/zh-cn/web/api/element/namespaceuri/index.html b/files/zh-cn/web/api/element/namespaceuri/index.html new file mode 100644 index 0000000000..540f00e9c2 --- /dev/null +++ b/files/zh-cn/web/api/element/namespaceuri/index.html @@ -0,0 +1,115 @@ +--- +title: Element.namespaceURI +slug: Web/API/Element/namespaceURI +translation_of: Web/API/Element/namespaceURI +--- +
{{APIRef("DOM")}}
+ +

Element.namespaceURI 是一个只读属性,它返回元素的命名空间,若该元素不在命名空间中则返回null .

+ +
+

在DOM4之前, 这个 API 在接口 {{domxref("Node")}} 中定义 .

+
+ +

语法

+ +
namespace = element.namespaceURI
+ +

例子

+ +

在这段代码中,我们检查了元素的{{domxref("localName")}}和namespaceURI。如果 namespaceURI 返回 XUL 命名空间, localName 返回"browser",于是这个节点被理解为是一个XUL <browser/>

+ +
if (element.localName == "browser" &&
+    element.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
+  // this is a XUL browser
+}
+ +

注意

+ +

这不是一个计算值,它是基于范围内的名称空间声明检查的名称空间查找的结果。节点命名空间在节点创建时被冻结。

+ +

在Firefox 3.5 以及之前的版本, HTML文档中的HTML元素的名称空间URI为 null。 在更早的版本中, 符合HTML5, 它是http://www.w3.org/1999/xhtml 如 XHTML。{{gecko_minversion_inline("1.9.2")}}

+ +

您可以使用DOM Level 2方法指定的namespaceURI创建一个元素 document.createElementNS

+ +

DOM本身不处理或执行名称空间验证。 它由DOM应用程序完成,以执行任何必要的验证。注意,名称空间前缀一旦与某个特定元素相关联,就不能更改。

+ +

说明

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("DOM4", "#dom-element-namespaceuri", "Element.namespaceuri")}}{{Spec2("DOM4")}}Initial definition
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support46.0[1]{{CompatGeckoDesktop("48.0")}}[1]{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatGeckoMobile("48.0")}}[1]{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

[1] 这API 可以预先在 {{domxref("Node")}} API中获得.

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf