Javascript 產生無限下拉式清單實現代碼

來源:互聯網
上載者:User

複製代碼 代碼如下://公司二維數組資料來源
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">



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.