//使用for...in语句
<script type="text/javascript">
var classmates,i;
classmates = new Array("张跃","马良","张力");
for (i in classmates) document.writeln("第"+(parselnt(i)+1)+"个同学是:"+classmates[i]) ;
</script>
3 回答
柠檬酸钠
TA贡献331条经验 获得超534个赞
第五行preseInt楼主写成了parseLnt,还有呢,就是一行代码也最好加上大括号,提高代码可读性
var classmates = new Array("张跃","马良","张力"); for (var i in classmates) { document.writeln("第"+(parseInt(i)+1)+"个同学是:"+classmates[i]); }
添加回答
举报
0/150
提交
取消