
定义和用法
data 属性设置或返回注释的文本。
语法
commentNode.data
实例
实例
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].data);
document.write("
");
}
}
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].data);
document.write("
");
}
}
上面的代码将输出:
125 Simple and Delicious Recipes (Hardcover)
在上面的实例中,我们使用一段循环和 if 语句来执行只针对 comment 节点的处理。comment 节点的节点类型是 8。
