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/hasattribute/index.html | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 files/zh-cn/web/api/element/hasattribute/index.html (limited to 'files/zh-cn/web/api/element/hasattribute') 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 +--- +
+ {{APIRef}}
+

概述

+

hasAttribute 返回一个布尔值,指示该元素是否包含有指定的属性(attribute)。

+

语法

+
var result = element.hasAttribute(attName);
+
+ +

例子

+
// 在为属性设置新值前检测该属性是否存在
+var d = document.getElementById("div1");
+
+if (d.hasAttribute("align")) {
+  d.setAttribute("align", "center");
+}
+

备注

+
+ {{DOMAttributeMethods}}
+

规范

+ -- cgit v1.2.3-54-g00ecf