可能的原因:
1 下标i越界;
2 认不出x(i);
……你在可能出错的位置加上alert("aaaa");执行一次就知道哪里错了。

解决方案 »

  1.   

    x(i)什么东东?
    改成document.getElementById("x"+i).innerHTML=oRoot.children.item((i-1)).text;
    试试。
      

  2.   

    你的myarray好像没有什么用?
    最好把相关的代码贴出来!
    你可以先试试
    把:x(i).innerHTML=oRoot.children.item((i-1)).text;
    改为:eval("x"+i).innerHTML=oRoot.children.item((i-1)).text;这个是正确的:
    if(oRoot.children != null)  
      {
       x1.innerHTML=oRoot.children.item(0).text;
       x2.innerHTML=oRoot.children.item(1).text;
       x3.innerHTML=oRoot.children.item(2).text;
       x4.innerHTML=oRoot.children.item(3).text;
       x5.innerHTML=oRoot.children.item(4).text;
       x6.innerHTML=oRoot.children.item(5).text;
      }
    下面这个不知道错在哪里。
    if(oRoot.children != null)  
      {
      var myarray = new Array();
      for (i = 1; i < 26; i++)
          {
           myarray[i] = i;
           x(i).innerHTML=oRoot.children.item((i-1)).text;
           }
      }
      

  3.   

    下面是所有的代码,是一个聊天室的显示部份,无刷新显示.xml里的数据。
    由于   n1.innerHTML=oRoot.children.item(0).getAttribute("name"); 有几十条,我想做成循环。x1是一个字符串对象吧。pp.asp
    --------------------------
    <SCRIPT language=javascript>
    function bar()
    {
    var oXMLDoc = new ActiveXObject('MSXML');
    oXMLDoc.url = "data.xml";
    var oRoot=oXMLDoc.root;
    if(oRoot.children != null)  
      {
       n1.innerHTML=oRoot.children.item(0).getAttribute("name");
       n2.innerHTML=oRoot.children.item(1).getAttribute("name");
       n3.innerHTML=oRoot.children.item(2).getAttribute("name");   t1.innerHTML=oRoot.children.item(0).getAttribute("time");
       t2.innerHTML=oRoot.children.item(1).getAttribute("time");
       t3.innerHTML=oRoot.children.item(2).getAttribute("time");   c1.innerHTML=oRoot.children.item(0).text;
       c2.innerHTML=oRoot.children.item(1).text;
       c3.innerHTML=oRoot.children.item(2).text;
      }
      var timeoutid = setTimeout("bar()",1500)
    }
    function callJS(jsStr)
    {
     return eval(jsStr)
    }
    </script><style>
    <!--
    #css1 {color:#D04000;}
    #css2 {color:#97AEB7;}
    body {font-size: 11pt; line-height:130%;}
    -->
    </style><body text="#0C74A7" bgcolor="#D9E6EF" onLoad="callJS('bar()')"><SCRIPT language=javascript>
    var myarray = new Array();
    for (i = 1; i < 26; i++)
    {
       myarray[i] = i;
       document.write ("<span id=n" + i + "></span><span id=css1>:</span> <span id=c" + i + "></span><span id=css2>&nbsp;(<span class=class2 id=t" + i + "></span>)</span><br>");
    }
    </script>data.xml
    -----------------------------------
    <?xml version="1.0" encoding="gb2312" ?>
    <chat>
    <content name="liu" time="2004-8-27 14:50:58">最前1条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前2条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前33条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前4条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前5条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前6条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前7条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前8条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前9条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前10条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前11条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前12条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前13条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前14条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前15条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前16条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前17条</content>
    <content name="liu" time="2004-8-27 14:50:58">最前18条</content>
    </chat>
      

  4.   

    问题解决了:
    用document.getElementById("x"+i).innerHTML=oRoot.children.item((i-1)).text;我在提问时忘了声明一下,x(i),这个i是一个字符串变量,就是说x1,x2,x3只要呈不同的数值排下来即可。pp.asp
    -------------------------------------
    <SCRIPT language=javascript>
    function bar()
    {
    var oXMLDoc = new ActiveXObject('MSXML');
    oXMLDoc.url = "data.xml";
    var oRoot=oXMLDoc.root;
    if(oRoot.children != null)  
      {
      var myarray_a = new Array();
      var myarray_a = new Array();
      var myarray_a = new Array();
      for (a = 1; a < 26; a++)
          {
           myarray_a[a] = a;
           document.getElementById("n"+a).innerHTML=oRoot.children.item(a-1).getAttribute("name");
           document.getElementById("t"+a).innerHTML=oRoot.children.item(a-1).getAttribute("time");
           document.getElementById("c"+a).innerHTML=oRoot.children.item(a-1).text;
           }
      }
      var timeoutid = setTimeout("bar()",1500)
    }
    function callJS(jsStr)
    {
     return eval(jsStr)
    }
    </script><style>
    <!--
    #css1 {color:#D04000;}
    #css2 {color:#97AEB7;}
    body {font-size: 11pt; line-height:130%;}
    -->
    </style><body text="#0C74A7" bgcolor="#D9E6EF" onLoad="callJS('bar()')"><SCRIPT language=javascript>
    var myarray = new Array();
    for (i = 1; i < 26; i++)
    {
       myarray[i] = i;
       document.write ("<span id=n" + i + "></span><span id=css1>:</span> <span id=c" + i + "></span><span id=css2>&nbsp;(<span class=class2 id=t" + i + "></span>)</span><br>");
    }
    </script>