您好,欢迎访问一九零五行业门户网

javascript怎么移除属性

移除方法:首先获取指定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高级教程
以上就是javascript怎么移除属性的详细内容。
其它类似信息

推荐信息