Home > Web Front-end > JS Tutorial > body text

Javascript generates infinite drop-down list implementation code_javascript skills

WBOY
Release: 2016-05-16 18:54:49
Original
1085 people have browsed it

Copy code The code is as follows:

//Company two-dimensional array data source
Office = [
["Dept", "ParentDept"],
["Business Department", "0"],
["Technology Department", "0"],
["Marketing Department ", "0"],
["www.yongfa365.com", "Business Department"],
["Business Department Xiao Yang", "Business Department"],
["Business Department Xiaocai" ", "Business Department"],
["Technology Department Lao Liu", "Technology Department"],
["Technology Department Lao Yang", "Technology Department"],
["Technology Department Lao Yang" dish", "Technical Department"],
["Mr. Liu of Marketing Department", "Marketing Department"],
["Mr. Yang of Marketing Department", "Marketing Department"],
["Marketing Department" "Rookie", "Marketing Department"]
]

//Province and city three-dimensional array data source
City3 = [
["Dept", "ParentId", "Id"],
["Beijing", "0", "010"],
["Shanxi", "0", "0359"],
["Chaoyang District", "010", "001"] ,
["Haidian District", "010", "002"],
["Dugezhuang", "001", "101"],
["Shilibao", "001" , "102"],
["Zhongguancun", "002", "201"],
["Shangdi", "002", "202"],
["Yuncheng area", "0359", "301"],
["Taiyuan City", "0359", "302"],
["Yongji City", "301", "311"],
[ "Community", "302", "312"]
];

//FillSelectTree("nowhaha", City3, "0", "311", -1)
//Select Control ID, data source, parent value, selected value, level (used to generate separators)
function FillSelectTree(SelectId, ArrObj, ParentValue, SelectedValue, NowI) {
StrObj = eval(document.getElementById (SelectId));

NowI ;

//Determine whether it is a secondary data source or a third-level data source
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 the 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 the string
function String(str, nowi) {
strtemp = "";
for (var i = 0; i < nowi; i ) {
strtemp = str;
}
return strtemp;
}


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute ]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!