From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/element/removeattribute/index.html | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 files/zh-cn/web/api/element/removeattribute/index.html (limited to 'files/zh-cn/web/api/element/removeattribute') diff --git a/files/zh-cn/web/api/element/removeattribute/index.html b/files/zh-cn/web/api/element/removeattribute/index.html new file mode 100644 index 0000000000..92a3d3844b --- /dev/null +++ b/files/zh-cn/web/api/element/removeattribute/index.html @@ -0,0 +1,54 @@ +--- +title: Element.removeAttribute() +slug: Web/API/Element/removeAttribute +tags: + - 属性 + - 方法 +translation_of: Web/API/Element/removeAttribute +--- +

{{ APIRef("DOM") }}

+ +

{{domxref("Element", "元素")}}方法 removeAttribute() 从指定的元素中删除一个属性。

+ +

语法

+ +
element.removeAttribute(attrName);
+
+ +

参数

+ +
+
属性名
+
{{domxref("DOMString")}}指定要从元素中移除的属性的名称。如果指定的属性不存在,则removeAttribute()返回,但不会生成错误。
+
+ +

返回值

+ +

IE 返回boolean类型值,其他返回undefined

+ +
+

注意:因为 removeAttribute() 不会返回任何有效值,你不能使用链式方法(连续使用方法,例如 document.body.removeAttribute("first").removeAttribute("second")…)连续移除多个属性。

+
+ +

使用说明

+ +

若要彻底移除一个属性的效果,应当使用  removeAttribute(),而不是使用 {{domxref("Element.setAttribute", "setAttribute()")}} 将属性值设置为  null。对于许多属性,如果仅将其值设为 null,这不会造达成和预期一样的效果。

+ +

{{ DOMAttributeMethods() }}

+ +

例子

+ +
// Given: <div id="div1" align="left" width="200px">
+document.getElementById("div1").removeAttribute("align");
+// Now: <div id="div1" width="200px">
+
+ +

规范

+ +

DOM Level 2 Core: removeAttribute (introduced in DOM Level 1 Core)

+ +

浏览器兼容性

+ + + +

{{Compat("api.Element.removeAttribute")}}

-- cgit v1.2.3-54-g00ecf