为什么if (node.attributes != null)正确,而if(node.attributes.length!=0)却出现错误

请问
为什么下面的函数会出错,
function Traverse(node)
{
nodes+=1;
if(node.attributes.length!=0)
nodes+=node.attributes.length;
for(var i=0;i

 1<node.childnodes.length;i++) (var="" <xml="" \---------------------------------------------------------------="" a="" access="" also="" an="" attributes="" attributes?="" because="" but="" call="" cannot="" complain="" doesn't="" example:="" for="" function="" has="" have="" i="0;i&lt;node.childNodes.length;" i++)="" id="xmldoc" if(node.attributes!="null)" is="" it="" length="" no="" node="" node,="" node.attributes="" node.attributes.length,="" nodes+="node.attributes.length;" none="" note,="" null="" null,="" object's="" property,="" since="" some="" text="" then="" there="" traverse(node)="" traverse(node.childnodes(i));="" when="" will="" you="" {="" }="" 而下面这个却成功="">
 2<root>hello</root>
 3
 4<script language="javascript">   
 5function window.onload()   
 6{   
 7var doc = xmldoc.documentElement;   
 8alert(doc.attributes.length);   
 9alert(doc.childNodes.length);   
10alert(doc.childNodes[0].nodeName + " has attributes? " + doc.childNodes[0].attributes)   
11}   
12</script></node.childnodes.length;i++)>
Published At
Categories with Web编程
comments powered by Disqus