XML DOM appendChild() 方法
Node 對象
定義和用法
appendChild() 方法把新的子節點追加到節點的子節點列表的末尾。
該方法返回新的子節點。
語法
實例
下面的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,創建節點(<edition>),并把它添加到第一個 <book> 節點的最后一個子節點的后面:
實例
xmlDoc=loadXMLDoc("books.xml");
newel=xmlDoc.createElement("edition");
x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);
document.write(x.getElementsByTagName("edition")[0].nodeName);
輸出:
edition
嘗試一下 ?
嘗試一下 Demos
appendChild() - 向所有的 <book> 節點追加一個子節點
Node 對象