哦上边的accessAllNodes(para.hasChildNodes[i]);
改为:accessAllNodes(para.childNodes[i]);

解决方案 »

  1.   

    para.hasChildNodes()"hasChildNodes" is a method of HTML Document Object Model, not property.
      

  2.   

    if(para.hasChildNodes())-->改成这样的话
    会报错啊能不能帮我修改一下呢?谢谢!
      

  3.   

    Secondly:"childNodes" property is not a collection, so do not use "in".<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000" onload="accessAllNodes(document)">
    <table>
    <tr>
    <td>a</td>
    </tr>
    </table></body>
    </html><SCRIPT LANGUAGE="JScript">
    function accessAllNodes(para) 
    {       
      if(para.hasChildNodes())
          {
    for(var i=0;i<para.childNodes.length;i++)
        accessAllNodes(para.childNodes[i]);          
      }
          else alert(para.nodeValue);
        
    }
    </SCRIPT>
      

  4.   

    现在改成这样,已经不死了,但是显示的都是“undefined”
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <SCRIPT LANGUAGE="JScript">
    function accessAllNodes(para) {       
      if(para.hasChildNodes)
              {
       for(i in para.childNodes)
           accessAllNodes(para.childNodes[i]);          
       }
       else alert(para.nodeName);   
    }
    </SCRIPT>
    <a href="#" onclick="accessAllNodes(document)">gfdsgfdgfd</a>
    </body>
    </html>
      

  5.   

    果然对了
    但是我还有一点要问:
    对于数组不是可以用in来访问吗?
    到底什么才算collection
      

  6.   

    ......................可能是我错了吧,C#里用in访问collection,而javascript里只能访问数组,访问不了collection,而childNodes应该是一个collection.我也迷糊里,别人给答吧。反正javascript的in用的不是很灵光,形同虚设。
      

  7.   

    看看下面代码var tmp = new Array();
    tmp["a"] = 1;
    tmp["b"] = 2;for (var i in tmp)
    alert(tmp[i]);只有tmp[i]才可以访问到数组中的内容,也就是说i是下标,i="a"...。而C#中int i in tmp的i确是tmp中的某一个内容,也就是说i=1,2....。
      

  8.   

    childNodes不是数组,是一个对象Xml Node对象。