removeAttribute与removeAttributeNode的区别

1、removeAttributeNode() 方法删除指定的属性,并以 Attr Node 对象返回被删除的属性。

例:

<!DOCTYPE html>
<html>
<body>

<h1 style="color:red">Hello World</h1>

<p id="demo">点击按钮来删除标题中的 style 属性节点。</p>

<button onclick="myFunction()">试一下</button>

<script>
function myFunction()
{
var n=document.getElementsByTagName("H1")[0];
var a=n.getAttributeNode("style");
n.removeAttributeNode(a);
}
</script>

</body>
</html>

2、removeAttribute() 方法删除指定的属性,此方法删除具有指定名称的属性,不返回值

例:

<!DOCTYPE html>
<html>
<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>

原文地址:https://www.cnblogs.com/moguzi12345/p/7595039.html