XML DOM replaceChild() 方法——Element 對(duì)象

2018-08-05 16:33 更新

XML DOM replaceChild() 方法


Element 對(duì)象參考手冊(cè) Element 對(duì)象

定義和用法

replaceChild() 方法替換子節(jié)點(diǎn)為其他節(jié)點(diǎn)。

如果成功該函數(shù)則返回被替換的節(jié)點(diǎn),如果失敗則返回 NULL。

語(yǔ)法

elementNode.replaceChild(new_node,old_node)

參數(shù) 描述
new_node 必需。規(guī)定新節(jié)點(diǎn)。
old_node 必需。規(guī)定要替換的子節(jié)點(diǎn)。


實(shí)例

下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,并替換第一個(gè) <book> 元素:

實(shí)例

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.documentElement;

//create a book element
newNode=xmlDoc.createElement("book");

y=xmlDoc.getElementsByTagName("book")[0]
//replace the first book node with the new node
x.replaceChild(newNode,y);

嘗試一下 ?

Element 對(duì)象參考手冊(cè) Element 對(duì)象
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)