zoukankan      html  css  js  c++  java
  • 替换元素节点replaceChild()

    replaceChild 实现子节点(对象)的替换。返回被替换对象的引用。 

    语法:

    node.replaceChild (newnode,oldnew ) 

    参数:

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

    注意: 

    1. 当 oldnode 被替换时,所有与之相关的属性内容都将被移除。 

    2. 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 inode = document.createElement("i");
            var itext = document.createTextNode("JavaScript");
            inode.appendChild(itext);
            var oldnode = document.getElementById("oldnode");
            oldnode.parentNode.replaceChild(inode,oldnode);
          }
      </script>
      
     </body>
    </html>
  • 相关阅读:
    12.静态目录
    11.Git线上操作
    10.分离的前后台交互
    09.后台主页应用
    08.前端主页
    爬虫介绍
    python2与python3爬虫中get与post对比
    HTML+CSS+JavaScript
    数据库 Mysql-mongodb-redis
    时频工具箱介绍与使用
  • 原文地址:https://www.cnblogs.com/sunxirui00/p/7504104.html
Copyright © 2011-2022 走看看