aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/hasattribute
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/element/hasattribute
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/element/hasattribute')
-rw-r--r--files/zh-cn/web/api/element/hasattribute/index.html31
1 files changed, 31 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/hasattribute/index.html b/files/zh-cn/web/api/element/hasattribute/index.html
new file mode 100644
index 0000000000..7d5a72f87c
--- /dev/null
+++ b/files/zh-cn/web/api/element/hasattribute/index.html
@@ -0,0 +1,31 @@
+---
+title: Element.hasAttribute()
+slug: Web/API/Element/hasAttribute
+translation_of: Web/API/Element/hasAttribute
+---
+<div>
+ {{APIRef}}</div>
+<h2 id="Summary" name="Summary">概述</h2>
+<p><code>hasAttribute</code> 返回一个布尔值,指示该元素是否包含有指定的属性(attribute)。</p>
+<h2 id="Syntax" name="Syntax">语法</h2>
+<pre class="syntaxbox"><var>var result</var> = <var>element</var>.hasAttribute(<var>attName</var>);
+</pre>
+<ul>
+ <li><code>result</code> 为返回的布尔值:<code>true</code> 或 <code>false</code>。</li>
+ <li><code>attName</code> 是一个字符串,表示属性的名称。</li>
+</ul>
+<h2 id="Example" name="Example">例子</h2>
+<pre class="brush:js">// 在为属性设置新值前检测该属性是否存在
+var d = document.getElementById("div1");
+
+if (d.hasAttribute("align")) {
+ d.setAttribute("align", "center");
+}</pre>
+<h2 id="Notes" name="Notes">备注</h2>
+<div>
+ {{DOMAttributeMethods}}</div>
+<h2 id="Specification" name="Specification">规范</h2>
+<ul>
+ <li><a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElHasAttr">DOM Level 2 Core: hasAttribute</a></li>
+ <li><a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-ElHasAttr">DOM Level 3 Core: hasAttribute</a></li>
+</ul>