javascript当中replaceChild的用法

例 1.6(replaceChildIEFF.html)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<BODY>
<div id="contain">
    <div id="a">a </div>
    <div id="b">b </div>
    <div id="c">c </div>
</div>

<script>
var contain = document.getElementById("contain");
var b =  document.getElementById("b");
var p =  document.createElement("p");/*这句话后创建了一个<p>*/
p.innerHTML="pText";
/*
Node.replaceChild() (Method)
A means of replacing child objects with new nodes and discarding the old ones.
The new node must be created using the createElement method.


Property/method value type: Node object
JavaScript syntax: - myNode.replaceChild(newNode, oldNode)
Argument list: newNode The node to be placed into the hierarchy
oldNode The node to be replaced
*/

contain.replaceChild( p , b  );
</script>
</BODY>
</HTML>


更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44594371/article/details/103064096

posted @ 2021-12-11 20:11  malala  阅读(121)  评论(0编辑  收藏  举报