码迷,mamicode.com
首页 > 其他好文 > 详细

替换元素节点replaceChild()

时间:2015-07-02 19:21:01      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

语法: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>

技术分享

替换元素节点replaceChild()

标签:

原文地址:http://www.cnblogs.com/gide/p/4616679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!