相思资源网 Design By www.200059.com

复制代码 代码如下:
//公司二维数组数据源
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;
}


[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]

标签:
Javascript,无限下拉列表

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“Javascript 生成无限下拉列表实现代码”

暂无Javascript 生成无限下拉列表实现代码的评论...