aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/hasattributens/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/element/hasattributens/index.html')
-rw-r--r--files/zh-cn/web/api/element/hasattributens/index.html47
1 files changed, 47 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/hasattributens/index.html b/files/zh-cn/web/api/element/hasattributens/index.html
new file mode 100644
index 0000000000..31adc64e89
--- /dev/null
+++ b/files/zh-cn/web/api/element/hasattributens/index.html
@@ -0,0 +1,47 @@
+---
+title: Element.hasAttributeNS()
+slug: Web/API/Element/hasAttributeNS
+tags:
+ - API
+ - 元素
+ - 属性
+ - 方法
+translation_of: Web/API/Element/hasAttributeNS
+---
+<p>{{ APIRef("DOM") }}</p>
+
+<h2 id="Summary" name="Summary">概述</h2>
+
+<p><code>hasAttributeNS</code> 返回一个布尔值,指示该元素是否包含有指定的属性(attribute)。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="eval"><em>result</em> =<em>element</em>.hasAttributeNS(<em>namespace</em>,<em>localName</em>)
+</pre>
+
+<ul>
+ <li><code>result</code> 为返回的布尔值:<code>true</code> 或 <code>false</code>。</li>
+ <li><code>namespace</code> 是一个字符串,表示属性的命名空间。</li>
+ <li><code>localName</code> 是一个字符串,表示属性的名称。</li>
+</ul>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<pre>// 在为属性设置值之前检测该属性是否存在
+var d = document.getElementById("div1");
+if (d.hasAttributeNS(
+ "http://www.mozilla.org/ns/specialspace/",
+ "special-align")) {
+ d.setAttribute("align", "center");
+}
+</pre>
+
+<h2 id="Notes" name="Notes">备注</h2>
+
+<p>该方法与<a href="https://developer.mozilla.org/zh-CN/docs/Web/API/element/hasAttribute" title="此页面仍未被本地化, 期待您的翻译!"><code>hasAttribute</code></a>类似,只是要检查的属性由命名空间和名称指定。只有使用命名空间的 XML 文档才使用方法</p>
+
+<p>{{ DOMAttributeMethods() }}</p>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElHasAttrNS">DOM Level 2 Core: hasAttributeNS</a></p>