html dom removeAttribute() 方法
html dom removeAttribute() 方法可以用来移除指定元素的属性。这个方法接收一个参数,即要移除的属性名称,并且返回 undefined。
element.removeAttribute(attribute);
下面是一个简单的使用示例:
// 获取元素 var elem = document.getElementById("myDiv"); // 移除属性 elem.removeAttribute("class");
在上面的示例中,我们使用 removeAttribute() 方法移除 id 为 myDiv 的元素的 class 属性。
removeAttribute() 方法可以移除任何元素的任何属性,包括特殊的属性,比如 id 和 style。
removeAttribute() 方法也可以用来移除自定义属性,比如 data-* 属性。
removeAttribute() 方法可以用来移除指定元素的属性,这样可以让我们更容易地控制元素的行为和外观。