XML DOM replaceChild() 方法
Element 對(duì)象
定義和用法
replaceChild() 方法替換子節(jié)點(diǎn)為其他節(jié)點(diǎn)。
如果成功該函數(shù)則返回被替換的節(jié)點(diǎn),如果失敗則返回 NULL。
語法
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ì)象
更多建議: