• 替换元素节点replaceChild()


    语法:node.replaceChild (newnode,oldnew ) 

    参数:

    newnode : 必需,用于替换 oldnew 的对象。 
    oldnew : 必需,被 newnode 替换的对象。

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    </head>
    <body>
    
    
      <div><b id="oldnode">JavaScript</b>是一个很常用的技术,为网页添加动态效果。</div>
      <a href="javascript:replaceMessage()"> 将加粗改为斜体</a>
      
        <script type="text/javascript">
          function replaceMessage(){
            var oldnode = document.getElementById("oldnode");  
            var oldHTML = oldnode.innerHTML;
            var newnode = document.createElement("i");
            oldnode.parentNode.replaceChild(newnode,oldnode);
            newnode.innerHTML = oldHTML;
           }    
      </script>
      
     </body>
    </html>

  • 相关阅读:
    64_l2
    64_l1
    64_k2
    64_k1
    64_j2
    64_j1
    64_g6
    64_g5
    64_g4
    64_g3
  • 原文地址:https://www.cnblogs.com/gide/p/4616679.html
Copyright © 2020-2023  润新知