可能的原因:
1 下标i越界;
2 认不出x(i);
……你在可能出错的位置加上alert("aaaa");执行一次就知道哪里错了。
1 下标i越界;
2 认不出x(i);
……你在可能出错的位置加上alert("aaaa");执行一次就知道哪里错了。
解决方案 »
- 如何获得input中password的密码输入的字符串的个数?
- 仿百度知道登陆
- JS 遍历头字母添加滚动条
- 怎么样屏蔽CTRL+N功能
- 挑战完美: 数字转中文大写程序.结果依据MS office2003.暂时没测出bug. code by 梅雪香.
- !!求救!!!!这段代码错在哪拉?????
- 表单提交时,如何把一个文本框的内容赋给一个隐藏的文本框元素,value属性值要怎么设?
- 在jsp页面中的java脚本<% %>取得一字符串v1, 在javascript中用 var vName = <%= v1%>给vName赋值, 结果总是报语法错, 应该如何赋值呢,
- 函数调用问题
- js 判断textbox是否有重复的中文
- 请教JS高手,如何在网页里操作Windows的日历控件啊?
- 关于FILE对像的问题????
改成document.getElementById("x"+i).innerHTML=oRoot.children.item((i-1)).text;
试试。
最好把相关的代码贴出来!
你可以先试试
把: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;
}
}
由于 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> (<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>
用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> (<span class=class2 id=t" + i + "></span>)</span><br>");
}
</script>