複製代碼 代碼如下://公司二維數組資料來源
Office = [
["Dept", "ParentDept"],
["業務部", "0"],
["技術部", "0"],
["市場部", "0"],
["www.yongfa365.com", "業務部"],
["業務部小楊", "業務部"],
["業務部小菜", "業務部"],
["技術部老柳", "技術部"],
["技術部老楊", "技術部"],
["技術部老菜", "技術部"],
["市場部柳先生", "市場部"],
["市場部楊先生", "市場部"],
["市場部菜鳥", "市場部"]
]
//省市三維數組資料來源
City3 = [
["Dept", "ParentId", "Id"],
["北京", "0", "010"],
["山西", "0", "0359"],
["朝陽區", "010", "001"],
["海澱區", "010", "002"],
["豆各莊", "001", "101"],
["十裡堡", "001", "102"],
["中關村", "002", "201"],
["上地", "002", "202"],
["運城地區", "0359", "301"],
["太原市", "0359", "302"],
["永濟市", "301", "311"],
["小區", "302", "312"]
];
//FillSelectTree("nowhaha", City3, "0", "311", -1)
//Select控制項ID,資料來源,父級值,選中值,第幾級(用來產生分隔字元)
function FillSelectTree(SelectId, ArrObj, ParentValue, SelectedValue, NowI) {
StrObj = eval(document.getElementById(SelectId));
NowI++;
//判斷它是二級資料來源,還是三級
if (ArrObj[0].length == 2)
{ ArrNum = 0; }
else
{ ArrNum = 2; }
//產生所有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]);
//選中預設值
if (ArrObj[i][ArrNum] == SelectedValue) {
StrObj.options[StrObj.length - 1].selected = true;
}
//遍曆
FillSelectTree(SelectId, ArrObj, ArrObj[i][ArrNum], SelectedValue, NowI);
}
}
}
//複製字串多少次
function String(str, nowi) {
strtemp = "";
for (var i = 0; i < nowi; i++) {
strtemp += str;
}
return strtemp;
}
xmlns="http://www.w3.org/1999/xhtml">