js三级联动

<html>
<head>
<title>级联菜单</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">


<script language="JavaScript">

function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined")
{
return false;
}
return true;
}

function change(v)
{
var str="0";
for(i=0;i<v;i++)
{
str+=("_"+(document.getElementById(s[i]).selectedIndex-1));
};
var ss=document.getElementById(s[v]);
with(ss)
{
  length = 0;
  options[0]=new Option(opt0[v],opt0[v]);
  if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
  {
   if(dsy.Exists(str))
   {
    ar = dsy.Items[str];
    for(i=0;i<ar.length;i++)
    {
    options[length]=new Option(ar[i],ar[i]);
    }
    if(v)options[1].selected = true;
   }
  }
  if(++v<s.length)
  {
  change(v);
  }
}
}

var dsy = new Dsy();

dsy.add("0",["总办","财政部","技术部"]);

dsy.add("0_0",["技术总办","销售总办","人事总办"]);

dsy.add("0_0_0",["1"]);
dsy.add("0_0_1",["2"]);
dsy.add("0_0_2",["3"]);


dsy.add("0_1",["财政一","财政二","财政三"]);

dsy.add("0_1_0",["1"]);
dsy.add("0_1_1",["1","2"]);
dsy.add("0_1_2",["1","2"]);



dsy.add("0_2",["eoms","sp","网管综合","技术支撑"]);

dsy.add("0_2_0",["1","2","3"]);
dsy.add("0_2_1",["1","3","2"]);
dsy.add("0_2_2",["1","3","2"]);
dsy.add("0_2_3",["1","3","2"]);


</script>

<script language = JavaScript>

var s=["s1","s2","s3"];
var opt0 = ["部门","组","人员"];
function setup()
{
for(i=0;i<s.length-1;i++)
  document.getElementById(s[i]).οnchange=new Function("change("+(i+1)+")");
change(0);
}

</script>

</head>
<body onLoad="setup()" >
<form name="frm">
<select id="s1">

</select>
<select id="s2">

</select>
<select id="s3">

</select>
</form>
</body>
</html> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值