1. 程式人生 > 其它 >javascript當中replaceChild的用法

javascript當中replaceChild的用法

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