zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    3.28
    03.21
    03.16
    03.15
    03.14小记
    [LC] 96. Unique Binary Search Trees
    [LC] 298. Binary Tree Longest Consecutive Sequence
    [LC] 102. Binary Tree Level Order Traversal
    [LC] 107. Binary Tree Level Order Traversal II
    [LC] 513. Find Bottom Left Tree Value
  • 原文地址:https://www.cnblogs.com/moguzi12345/p/7595039.html
Copyright © 2011-2022 走看看