这对我来说其实很奇怪。我不知道如何动态创建多维数组。我想创建一个三级下拉列表,所以我想我需要一个三维数组来存储值。如何创建三维数组?
<script language=javascript>
var aCourse=new Array();
aCourse[0]=new Array();
aCourse[1]=new Array();
aCourse[2]=new Array();
aCourse[3]=new Array();
aCourse[0][0]="Select...";
aCourse[1][0]="Select...";
aCourse[1][1]="T Square";
aCourse[1][2]="V Square";
aCourse[1][3]="S Square";
aCourse[1][4]="B Square";
aCourse[1][5]="G Square";
aCourse[2][0]="Select...";
aCourse[2][1]="N Square";
aCourse[2][2]="W Square";
aCourse[3][0]="Select…";
aCourse[3][1]="J Square";
aCourse[3][2]="M Square";
function ChangeCourse()
{
var i,
iCategoryIndex;
iCategoryIndex=document.frm.optCategory.selectedIndex;
iCourseCount=0;
while (aCourse[iCategoryIndex][iCourseCount]!=null)
iCourseCount++;
document.frm.optCourse.length=iCourseCount;
for (i=0;i<=iCourseCount-1;i++)
document.frm.optCourse[i]=new Option(aCourse[iCategoryIndex][i]);
document.frm.optCourse.focus();
}
</script>
<body ONfocus=ChangeCourse()>
<h3>Choose category…</h3>
<form name="frm">
<p>Category:
<select name="optCategory" size="1" onChange=ChangeCourse()>
<option>Select…</option>
<option>Soccer</option>
<option>Cricket</option>
<option>Rugby</option>
</select>
</p>
<p>Fields
<select name="optCourse" size="1">
<option>Select…</option>
</select>
</p>
</form>