XML DOM appendData() 方法
Comment 對象
定義和用法
appendData() 方法向注釋節(jié)點的末尾添加數據。
語法
commentNode.appedData(string)
參數 | 描述 |
string | 必需。向注釋節(jié)點添加的字符串。 |
實例
下面的代碼片段使用 loadXMLDoc() 把 "books_comment.xml" 載入 xmlDoc 中,并向第一個注釋元素追加文本:
實例
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
x[i].appendData(" Special Offer");
document.write(x[i].data);
document.write("
");
}
}
輸出:
125 Simple and Delicious Recipes (Hardcover) Special Offer
嘗試一下 ? 在上面的實例中,我們使用一段循環(huán)和 if 語句來執(zhí)行只針對 comment 節(jié)點的處理。comment 節(jié)點的節(jié)點類型是 8。
Comment 對象
更多建議: