首页 新闻 会员 周边 捐助

js中二维数组的问题,求救

0
[已关闭问题]
<P>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<BR>"<A href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</A>"&gt;<BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;title&gt;Untitled Document&lt;/title&gt;<BR>&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<BR>&lt;link href="images/1.jpg" /&gt;<BR>&lt;/head&gt;<BR>&lt;script language="javascript"&gt;<BR>function showimages(x,y)<BR>{<BR>&nbsp;var images=new Array(27,33)<BR>&nbsp;var time=1<BR>&nbsp;for(var i=0;i&lt;28;i++)<BR>&nbsp;{<BR>&nbsp;&nbsp;for(var j=0;j&lt;34;j++)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;images[i,j]=""+time+".jpg"&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//alert(images[i,j])<BR>&nbsp;&nbsp;&nbsp;time++<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;alert(images[27,33])&nbsp;<BR>&nbsp;alert(time)<BR>&nbsp;<BR>&nbsp;var showimage=new Array(7,7)<BR>&nbsp;var z=0;<BR>&nbsp;<BR>&nbsp;for(var a=x;a&lt;x+7;a++)<BR>&nbsp;{<BR>&nbsp;&nbsp;var w=0;<BR>&nbsp;&nbsp;for(var b=y;b&lt;y+7;b++)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;showimage[z,w]=images[a,b]&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;alert(images[a,b])&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;alert(images[0,0])&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;w++&nbsp;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;z++&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;<BR>&nbsp;}<BR>}</P> <P>&lt;/script&gt;</P> <P>&lt;body&gt;<BR>&lt;form name="form1" method="post" action=""&gt;<BR>&nbsp; &lt;input type="button" name="Submit" value="Submit" onClick="showimages(0,0)"&gt;<BR>&lt;/form&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt;<BR>页面执行为何alert(images[0,0])=921.jpg</P> <P>alert(images[a,b]),第一次为953.jpg</P>
问题补充: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <link href="images/1.jpg" /> </head> <script language="javascript"> function showimages(x,y) { var images=new Array(27,33) var time=1 for(var i=0;i<28;i++) { for(var j=0;j<34;j++) { images[i,j]=""+time+".jpg" //alert(images[i,j]) time++ } } alert(images[27,33]) alert(time) var showimage=new Array(7,7) var z=0; for(var a=x;a<x+7;a++) { var w=0; for(var b=y;b<y+7;b++) { showimage[z,w]=images[a,b] alert(images[a,b]) alert(images[0,0]) w++ } z++ } } </script> <body> <form name="form1" method="post" action=""> <input type="button" name="Submit" value="Submit" onClick="showimages(0,0)"> </form> </body> </html> 页面执行为何alert(images[0,0]) =921.jpg ,alert(images[a,b]) 第一次为953.jpg
zjianjun/Andy的主页 zjianjun/Andy | 初学一级 | 园豆:25
提问于:2008-08-11 21:11
< >
分享
其他回答(1)
0
1、二维数组声明方式是下面这样的: var images=new Array(); for(var i=0;i<27;i++){ images[i]=new Array(); } 2、二级数组使用方式应该是这样子的: alert(images[0][0]); 声明确实比较麻烦,需要先声明第一维,然后循环生成第二维 可以搜索一下有关javascript二维数组的知识,简单,但用起来比较麻烦
丁学 | 园豆:18730 (专家六级) | 2008-08-12 09:26
0
建议用firebug调试下 很方便的
小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2008-08-12 13:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册