蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年8月25日 8:28

javascript问题,不知如何描述

[code]
myImages[0] = new Image(22,25);
myImages[0].src ='images/0.jpg';
myImages[1] = new Image(22,25);
myImages[1].src ='images/1.jpg';
myImages[2] = new Image(22,25);
myImages[2].src ='images/2.jpg';
myImages[3] = new Image(22,25);
myImages[3].src ='images/3.jpg';
myImages[4] = new Image(22,25);
myImages[4].src ='images/4.jpg';
myImages[5] = new Image(22,25);
myImages[5].src ='images/5.jpg';
myImages[6] = new Image(22,25);
myImages[6].src ='images/6.jpg';
myImages[7] = new Image(22,25);
myImages[7].src ='images/7.jpg';
myImages[8] = new Image(22,25);
myImages[8].src ='images/8.jpg';
myImages[9] = new Image(22,25);
myImages[9].src ='images/9.jpg';
[/code]

要执行以上代码,但是一个个写很麻烦,所以用循环写出来,问题是怎么放进去直接执行?

[html]
<script>for (i=0;i<10;i++){
document.write(
"myImages["+
i+
"] = new Image(22,25);<br>"+
"myImages["+
i+
"].src ='images/"+
i+
".jpg';<br>"
)
}
</script>
[/html]

var myImages = [];
for (i=0;i<10;i++){
  myImages[i] = new Image(22,25);
  myImages[i].src ="images/"+i+".jpg";
}

[code]
...

for (var i=0;i<10;i++){
  myImages[i] = new Image(22,25);
  myImages[i].src ='images/'+i+'.jpg';
}
...
[/code]

<script>
var myImages = [];
for (i=0;i<10;i++){
myImages[i] = new Image(22,25);
myImages[i].src ="images/"+i+".jpg";
}
</script>




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com