removeAttribute()方法从元素中删除具有指定名称的属性。
注意:由于removeAttribute()不返回值,所以不能将多个调用链接在一起来一次性删除多个属性。
使用getAttribute()方法可返回元素的属性值。
使用setAttribute()方法可添加新属性或更改元素上现有属性的值。
element.removeAttribute(attrName)
document.getElementsByTagName("H1")[0].removeAttribute("class");测试看看‹/›所有浏览器完全支持removeAttribute()方法:
| Method |  |  |  |  |  | 
| removeAttribute() | 是 | 是 | 是 | 是 | 是 | 
| 参数 | 描述 | 
|---|---|
| attrName | 字符串,表示要从元素中删除的属性的名称 | 
| 返回值: | Undefined | 
|---|---|
| DOM版本: | DOM 2级 | 
找出锚元素是否具有href属性。如果存在href,使用removeAttribute删除href属性:
var a = document.getElementById("myLink");
if (a.hasAttribute("href")) {
a.removeAttribute("href");
}测试看看‹/›HTML教程:HTML属性
HTML DOM参考:getAttribute()方法
HTML DOM参考:setAttribute()方法
HTML DOM参考:hasAttribute()方法