javascript怎么移除属性
时间:2021-04-28 来源:互联网
今天PHP爱好者给大家带来移除方法:首先获取指定DOM对象,然后使用removeAttribute()方法来移除属性;语法格式“DOM对象.removeAttribute(元素的属性名)”。removeAttribute()方法可以删除具有指定名称的属性。希望对大家有所帮助。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
在javascript中,可以利用removeAttribute() 方法来删除属性。
removeAttribute() 方法可以删除具有指定名称的属性,无返回值。
语法:
element.removeAttribute(attributename)
参数attributename:要移除的属性的名称,不可省略。
示例:删除 header 元素的 style 属性
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除 header 元素的 style 属性</title>
</head>
<body>
<h1 style="color:red">Hello World</h1>
<p id="demo">点击按钮来删除标题中的 style 属性。</p>
<button onclick="myFunction()">试一下</button>
<script>
function myFunction() {
document.getElementsByTagName("H1")[0].removeAttribute("style");
}
</script>
</body>
</html>
效果图:
以上就是javascript怎么移除属性的详细内容,更多请关注php爱好者其它相关文章!
-
瞳孔地震是什么梗?揭秘网络热词背后的爆笑瞬间! 2025-09-09
-
统一六国的梗是什么梗?揭秘秦始皇爆笑网络热梗背后的真相! 2025-09-09
-
-
怪兽八号手游核爆配队详解-适用所有主C 2025-09-09
-
逆水寒手游十月版本前瞻-航母联动特色逆水杀曝光 2025-09-09
-
女神异闻录:夜幕魅影P5X-片山久未技能简读搭配推荐 2025-09-09