<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>二维数组</title>
<script type="text/javascript">
var mar=new Array();
for(var a=0;a<3;a++)
{
mar[a]=new Array();
for(var b=0;b<6;b++)
{
mar[a][b]=a*b;
}
}
document.write(mar[a][b]);
</script>
</head>
<body>
</body>
</html>
将document.write(mar[a][b]);放到a*b;的后面, 因为ab是在循环中定义的,循环外面用不了ab
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>二维数组</title>
<script type="text/javascript">
var mya=new Array();
for(var i=0;i<3;i++){
mya[i]=new Array();
for(var j=0;j<6;j++){
mya[i][j]=i*j;
}
}
document.write(mya[2][5]);
</script>
</head>
<body>
</body>
</html>
<script type="text/javascript"> var mar=new Array(); for(var a=0;a<3;a++) { mar[a]=new Array(); for(var b=0;b<6;b++) { mar[a][b]=a*b; document.write(mar[a][b]); } } </script>
document.write(mar[a][b]);中的[a][b]要输入具体数值。例如document.write(mar[2][4]);