<script language="JavaScript">
var classmate = new Array("2", "3", "6", "7", "8", "10");
var classname2="sdfsfsfsdfsfs";
var classname3="qweqweqweq";
var classname6="zczczxc";
var classname7="poipiopio";
var classname8="lkjljkl";
var classname10="mbnmnbmb";
for(i in classmate){
document.write(??????+classmate[i]+"<br/>");
</script>
要循环输出 怎么解决啊? 谢谢
參考答案:其实你少了一个},那些问号要用引号括起来,或是用变量代替。
以下代码测试通过,
<script language="JavaScript">
var classmate= new Array("2","3","6","7","8","10");
var classname2="sdfsfsfsdfsfs";
var classname3="qweqweqweq";
var classname6="zczczxc";
var classname7="poipiopio";
var classname8="lkjljkl";
var classname10="mbnmnbmb";
//按照你原意
for(i in classmate){
document.write("aaaa"+classmate[i]+"<br/>");
}
//输出classname
document.write("<p>输出classname<br>");
for(i in classmate){
document.write("aaaa"+eval("classname"+classmate[i])+"<br/>");
}
</script>