DOM NamedNodeMap对象length属性

length属性给出此映射中的节点数。有效子节点索引的范围是0length-1(包括0length-1)。

语法

以下是使用length属性的语法。

nodemapObject.length

示例

文件:node.xml 的内容如下 -

<Company> 
   <Employee category = "Technical" id = "firstelement"> 
      <FirstName>Susen</FirstName> 
      <LastName>Su</LastName> 
      <ContactNo>1584567890</ContactNo> 
      <Email>susen@xuhuhu.com</Email> 
   </Employee>  

   <Employee category = "Non-Technical"> 
      <FirstName>Max</FirstName> 
      <LastName>Su</LastName> 
      <ContactNo>1334667898</ContactNo> 
      <Email>maxsu@xuhuhu.com</Email> 
   </Employee>  

   <Employee category = "Management"> 
      <FirstName>Min</FirstName> 
      <LastName>Su</LastName> 
      <ContactNo>1364562350</ContactNo> 
      <Email>minsu@xuhuhu.com</Email> 
   </Employee> 
</Company>

以下示例演示了length 属性的用法 -

<!DOCTYPE html>
<html>
   <meta charset="utf-8"/>
   <head></head>
   <body>
      <script>
         if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
         } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
         xmlhttp.open("GET","/node.xml",false);
         xmlhttp.send();
         xmlDoc = xmlhttp.responseXML;

         x = xmlDoc.getElementsByTagName("Employee");
         document.write("长度为 : ");
         document.write(x.item(0).attributes.length);
      </script>
   </body>
</html>

执行上面示例代码,得到以下结果 -


上一篇: DOM NamedNodeMap对象 下一篇: DOMImplementation对象