参考下列代码:
< head>
< title>多级关联菜单
< meta http-equiv="Content-Type" content="text/html; charset=gb2312">
< head>
< 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
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
}
}
if(++v
}
var dsy = new Dsy();
dsy.add("0",["安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙古","宁夏","青海","山东","山西","陕西","上海","四川","天津","西藏","新疆","云南","浙江","重庆"]);
dsy.add("0_0",["安庆","蚌埠","巢湖","池州","滁州","阜阳","合肥","淮北","淮南","黄山","六安","马鞍山","宿州","铜陵","芜湖","宣城","亳州"]);
//-->
< /script>
< script language = JavaScript>
< !--
var s=["s1","s2","s3"];
var opt0 = ["-省-","-市-"];
function setup()
{
for(i=0;i
change(0);
}
//-->
< /script>
< /head>
< body onload="setup()">
< form name="frm">
< select id="s1">
< select id="s2">
< /form>
< /body>
< /html>
你这个是静态的还是从数据库查的?
如果是静态的 网上很多例子, 把数据写到两个js数组里就可以了
如果是动态的,一般用的是Ajax来做,如果你觉得这个比较难,那么我给你个简单的思路
就是当我选择第一个下拉菜单的时候,触发onchange事件 提交表单,把选择的value提交到servlet
然后通过这个value把第二个下拉菜单要显示的内容查出来,再传到这个页面上显示
静态的非常简单,用javascript写个onchnage()事件就搞定了。
祝好运!---------^-^臭即是香^-^!
数据写到两个js数组里就可以