XML DOM length 屬性
Comment 對象
定義和用法
length 屬性返回注釋節(jié)點中文本的長度(以字符計)。
語法
實例
下面的代碼片段使用 loadXMLDoc() 把 "books_comment.xml" 載入 xmlDoc 中,并從第一個 <title> 元素取得文本節(jié)點數(shù)據(jù)和長度:
實例
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
document.write(x[i].length);
document.write("
");
}
}
上面的代碼將輸出:
44
嘗試一下 ? 在上面的實例中,我們使用一段循環(huán)和 if 語句來執(zhí)行只針對 comment 節(jié)點的處理。comment 節(jié)點的節(jié)點類型是 8。
Comment 對象
更多建議: