XML DOM 教程

XML DOM length 属性

Comment对象参考手册 Comment 对象

定义和用法

length 属性返回注释节点中文本的长度(以字符计)。

语法

commentNode.length

实例

实例


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

在上面的实例中,我们使用一段循环和 if 语句来执行只针对 comment 节点的处理。comment 节点的节点类型是 8。

Comment 对象参考手册 Comment 对象其他扩展

用微信扫一扫

收藏