急需两个下拉菜单联动的源代码,高分相赠!急

chummy 2004-11-27 03:13:52
那位仁兄能给我一个两个下拉菜单联动的源代码.高分相赠!急

选择第一个菜单(大的类别)时,下面的第二个菜单(小的类别)内容变化
就好像CSDN论坛的选择搜索范围一样.
我就是要做这样的搜索界面.很赶时间,因为不熟悉javascript,所以拜托各位.谢谢了.
...全文
101 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
haosee 2004-11-27
还有个,只是不怎么好:

<select name=year></select>
<select name=month></select>
<select name=date></select>
<select name=clock></select>
<input name=result>

<script>
var arrSel=["year","month","date","clock"];//arrSel定义了要修改的下拉框和xml数据的节点名称
</script>

<xml id=xmldata>
<xmldata>
<year value="2000">
<month value="4">
<date value="14">
<clock value="一点" />
<clock value="三点" />
</date>
<date value="17">
<clock value="一点" />
</date>
</month>
<month value="5">
<date value="15">
<clock value="一点" />
<clock value="四点" />
<clock value="七点" />
</date>
</month>
</year>
<year value="2001">
<month value="7">
<date value="16">
<clock value="一点" />
<clock value="五点" />
<clock value="九点" />
</date>
</month>
</year>
</xmldata>
</xml>

<script>
function qswhXml(num){
/******* by qiushuiwuhen(2002-5-17) ********/
var i,j,arrTemp=[];
for(i=0;i<num;i++)arrTemp[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].text
if(num==arrSel.length){//这里处理最后的数据。
document.all("result").value="选中了("+arrTemp+")";return;
}
with(document.all(arrSel[num])){
length=0
var obj=document.all.xmldata.XMLDocument.childNodes[0];
for(i=0;i<num;i++)obj=obj.selectSingleNode(arrSel[i]+'[@value="'+arrTemp[i]+'"]');
for(i=0;i<obj.childNodes.length;i++)options[length++].text=obj.childNodes[i].getAttribute("value");
onchange=new Function("qswhXml("+(num+1)+")");
onchange();
}
}
qswhXml(0);
</script>

回复
haosee 2004-11-27
这个最好:

<BODY>
<SELECT NAME="s1"><option>需要JavaScript才能正确显示</SELECT>
<SELECT NAME="s2"></SELECT>
<SELECT NAME="s3"></SELECT>
<SELECT NAME="s4"></SELECT>

<SCRIPT LANGUAGE="JavaScript">
<!--



//选择框的名字
selector = [ "s1", "s2", "s3", "s4" ];



//选择项: "名字", "值", 子选择
menu = [
"地球","1",
[
"中国","86",
[
"北京","BJ",
[
"--","1",null
],
"四川","SC",
[
"成都","28",null,
"乐山","",null,
"攀枝花","",null,
"自贡","",null,
"德阳","",null,
"绵阳","",null
]
],
"米国","1",
[
"加利福尼亚","CA",
[
"旧金山","1",null,
"洛杉矶","2",null
],
"华盛顿","WA",
[
"西雅图","seattle",null
]
]
],
"火星","2",
[
"大峡谷","86",
[
"小山丘","BJ",
[
"A地区","28",null,
"B地区","",null,
"C地区","",null
]
]
]
];



function wizz(level)
{
if( level == 0 )
a = menu;
else
{
str = "menu";
for( i=0; i<level; i++ )
str += "[" + (document.all[selector[i]].selectedIndex * 3 + 2) + "]";
a = eval(str);
}
if( a == null ) return;

s = document.all[selector[level]];
i = s.length;
while( i > 0 ) s.options[--i] = null;
while( i < Math.floor(a.length/3) )
s.options[i] = Option( a[i*3], a[i++*3+1] );
s.onchange = Function("wizz(" + (level+1) + ")");
wizz(level+1);
}



wizz(0);

//-->
</SCRIPT>



</BODY>
</HTML>

回复
sdpong 2004-11-27
<HTML>

  <HEAD>

  <SCRIPT LANGUAGE="JavaScript">

  function setcity() {

  switch (document.shengshi.sheng.value) {

  case '河北' :

  var labels = new Array("石家庄","沧州","唐山");

  var values = new Array("sjz","cz","ts");

  break;

  case '山东' :

  var labels = new Array("济南","青岛","烟台");

  var values = new Array("jn","qd","yt");

  break

  }

  // 清空市列表选择框的内容

  document.shengshi.city.options.length = 0;

  // 从数组中添加内容

  for(var i = 0; i <labels.length; i++) {

  document.shengshi.city.add(document.createElement("OPTION"));

  document.shengshi.city.options[i].text=labels[i];

  document.shengshi.city.options[i].value=values[i];

  }

  // 选择第一个选项

  document.shengshi.city.selectedIndex = 0;


  }

  </SCRIPT>

  </HEAD>

  <BODY>

  <FORM NAME="shengshi">

  省:

  <SELECT NAME="sheng" OnChange="setcity()">

  <OPTION VALUE="河北">河北</OPTION>

  <OPTION VALUE="山东" SELECTED>山东</OPTION>

  </SELECT>

  市:

  <SELECT NAME="city"></SELECT>

  </FORM>

  <!-- 执行初始化选择列表 -->

  <SCRIPT LANGUAGE="JavaScript">

  setcity();

  </SCRIPT>

  </BODY>

  </HTML>
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2004-11-27 03:13
社区公告
暂无公告