定义和用法
removeAttribute() 方法删除指定的属性
查看类似方法 removeAttributeNode() 。
所有主要浏览器都支持 removeAttribute() 方法
语法
element.removeAttribute(attributename)参数s
| 参数 | 类型 | 描述 |
|---|---|---|
| attributename | String | 必需。规定要删除的属性的名称。 |
返回值
没有返回值。
技术细节
| DOM 版本 | Core Level 1 Element Object |
|---|
实例
删除头部元素的 style 属性:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
</head>
<body>
<h1 style="color:red">Hello World</h1>
<p id="demo">点击下面的按钮删除上面的标题的样式属性</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
document.getElementsByTagName("H1")[0].removeAttribute("style");
};
</script>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/domtips/4514.html
支付宝
微信