Copy Code code as follows:
Company two-dimensional array data source
Office = [
["Dept", "parentdept"],
["Business", "0"],
[Technical department], "0",
["Marketing department", "0"],
["Www.yongfa365.com", "Business Department"],
["Business department Xiao Yang", "Business Department"],
["Business Side Dishes", "business Department"],
[Technical department old Willow], "technology department"],
[Technical Department Lao Yang], "technology department",
[Technical Department of Old vegetables], "technology department"],
[Mr. Liu of the marketing department], "marketing department",
[Mr. Yang of the marketing department], "marketing department",
["Marketing Rookie", "marketing department"]
]
Three-dimensional array data source of provinces
City3 = [
["Dept", "ParentID", "Id"],
["Beijing", "0", "010"],
["Shanxi", "0", "0359"],
["Chaoyang District", "010", "001"],
["Haidian", "010", "002"],
["Bean Village", "001", "101"],
["Ten Li Bao", "001", "102"],
["Zhongguancun", "002", "201"],
["Ground", "002", "202"],
["Yuncheng area", "0359", "301"],
["Taiyuan City", "0359", "302"],
["Yongji", "301", "311"],
["Community", "302", "312"]
];
Fillselecttree ("Nowhaha", City3, "0", "311",-1)
Select control ID, data source, parent value, selected value, level (used to produce separator)
function Fillselecttree (Selectid, Arrobj, Parentvalue, SelectedValue, Nowi) {
Strobj = eval (document.getElementById (Selectid));
nowi++;
To determine if it is a level two data source or a level three
if (arrobj[0].length = 2)
{arrnum = 0;}
Else
{arrnum = 2;}
Generate All option
for (var i = 0; i < arrobj.length; i++) {
if (arrobj[i][1] = = Parentvalue) {
Strobj.options[strobj.length] = new Option (String ("", Nowi) + arrobj[i][0], arrobj[i][arrnum]);
Select default Value
if (arrobj[i][arrnum] = = SelectedValue) {
Strobj.options[strobj.length-1].selected = true;
}
Traverse
Fillselecttree (Selectid, Arrobj, Arrobj[i][arrnum], SelectedValue, NOWI);
}
}
}
How many times to copy a string
function String (str, NOWI) {
strtemp = "";
for (var i = 0; i < Nowi; i++) {
strtemp + + str;
}
return strtemp;
}
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title></title> </pead> <b ody> <script language= "JavaScript" type= "Text/javascript" >//company two-dimensional array data source Office = [["Dept", "parentdept"], [" Business "," 0 "], [" Technical department "," 0 "], [" Marketing department "," 0 "], [" Business Department small Willow "," Business Department "], [" Business department Xiao Yang "," Business Department "], [" Business Side vegetable "," business Department "], [" Technical Department Old Willow "," technology department "], [" Technical Lao Yang "," technical department ", [" technical Department of the old Dish "," technical department "], [Mr. Liu of Marketing department], [marketing department], [" Marketing department "," marketing department "], [" Marketing Rookie "," marketing Department "]]//City three-dimensional array data source City3 = [[] Dept "," ParentID "," Id "], [" Beijing "," 0 "," 010 "], [" Shanxi "," 0 "," 0359 "], [" Chaoyang District "," 010 "," 001 "], [" Haidian "," 010 "," 002 "], [" Beans Zhuang "," 001 "," 101 "], [" Ten-Fort "," 001 "," 102 "], [" Zhongguancun "," 002 "," 201 "], [" On the Ground "," 002 "," 202 "], [" Yuncheng area "," 0359 "," 301 "], [" Taiyuan City "," 0359 "," 302 "], [" Yongji "," 301 "," 311 "], [" Community "," 302 "," 312 "]]; Fillselecttree ("Nowhaha", City3, "0", "311",-1)//select control ID, data source, parent value, selected value, the first few levels (used to produce delimiters) function fillselecttree (Selectid, Arrobj, Parentvalue, SelectedValue, nowi) {strobj = eval (document.getel Ementbyid (Selectid)); nowi++; Determine if it is a level two data source, or level three if (Arrobj[0].length = 2) {arrnum = 0;} else {arrnum = 2;} Generate All option for (var i = 0; i < arrobj.length i++) {if (arrobj[i][1) = = Parentvalue) {Strobj.options[strobj.leng TH] = new Option (String ("", Nowi) + arrobj[i][0], arrobj[i][arrnum]); Select the default value if (arrobj[i][arrnum] = = SelectedValue) {strobj.options[strobj.length-1].selected = true; }//Traverse Fillselecttree (Selectid, Arrobj, Arrobj[i][arrnum], SelectedValue, NOWI); }}///copy string number of times function string (str, nowi) {strtemp = ""; for (var i = 0; i < Nowi i++) {strtemp = = str; return strtemp; } </script> <pr/> <select id= "Nowhaha" > </select> <script language= "JavaScript" Type= "Tex T/javascript "> Fillselecttree (" Nowhaha ", City3," 0 "," 311 ",-1) </script> <select id=" Nowoffice "> </select> <script language= "JavaScript" type= "Text/javascript" > Fillselecttree ("Nowoffice", Office, "0", "Business Department small Willow",-1 </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]