CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> two-dimensional functions </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
/*
An array of rowlength and collength is formed.
*/
Function darray (rowlength, collength ){
VaR darray = new array (rowlength );
// Add collength data to each column
For (VAR I = 0; I <rowlength; I ++ ){
Darray [I] = new array (collength );
}
Return darray;
}
Function getarray (){
VaR darray = new darray (10, 10 );
Darray [0] [10] = 100;
Darray [0] [1] = "I like JS ";
Alert (darray [0] [10] + "," + darray [0] [1]);
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" value = "get two-dimensional" onclick = "getarray ()"/>
</Body>
</Html>
Bind a select drop-down menu by declaring a two-dimensional arrayCopy code The Code is as follows: <HTML>
<Head>
<Title> example of dynamically changing the drop-down menu content </title>
</Head>
<Script language = JavaScript>
// Define a two-dimensional array aarray to store city names.
VaR acity = new array ();
Acity [0] = new array ();
Acity [1] = new array ();
Acity [2] = new array ();
Acity [3] = new array ();
// Assign a value. The cities of each province are stored in one row of the array.
Acity [0] [0] = "-- Please select --";
Acity [1] [0] = "-- Please select --";
Acity [1] [1] = "Guangzhou City ";
Acity [1] [2] = "Shenzhen City ";
Acity [1] [3] = "Zhuhai City ";
Acity [1] [4] = "Shantou City ";
Acity [1] [5] = "Foshan City ";
Acity [2] [0] = "-- select --";
Acity [2] [1] = "Changsha City ";
Acity [2] [2] = "Zhuzhou city ";
Acity [2] [3] = "Xiangtan city ";
Acity [3] [0] = "-- select --";
Acity [3] [1] = "Hangzhou City ";
Acity [3] [2] = "Suzhou City ";
Acity [3] [3] = "Wenzhou City ";
Function changecity ()
{
VaR I, iprovinceindex;
Iprovinceindex = Document. frm. optprovince. selectedindex;
Icitycount = 0;
While (acity [iprovinceindex] [icitycount]! = NULL)
Icitycount ++;
// Calculate the number of cities in the selected Province
Document. frm. optcity. Length = icitycount; // change the number of options in the drop-down menu
For (I = 0; I <= iCityCount-1; I ++) // change the content of the drop-down menu
Document. frm. optcity [I] = New Option (acity [iprovinceindex] [I]);
Document. frm. optcity. Focus ();
}
</SCRIPT>
<Body onfocus = changecity ()>
<H3> select your province and city <Form name = "frm">
<P> province:
<Select name = "optprovince" size = "1" onchange = changecity ()>
<Option> -- select -- </option>
<Option> Guangdong </option>
<Option> Hunan Province </option>
<Option> Zhejiang </option>
</SELECT>
</P>
<P> city:
<Select name = "optcity" size = "1">
<Option> -- select -- </option>
</SELECT>
</P>
</Form>
</Body>
</Html>