回 帖 发 新 帖 刷新版面

主题:[原创]下拉菜单联动,终于搞定![share]

很早以前就想实现这个功能,因为本人能力有限,在查了不少资料后,终于在自己的系统实现了这一功能,我把代码贴出来,希望能对大家在帮助:
<script LANGUAGE="javascript">
<!--
var onecount;  '循环变量
var onecount1;
onecount=0;
onecount1=0;
subcat = new Array();
othercat = new Array();
subcat[0] = new Array("99-所有产品","3","99");    '自定义数组及内容
subcat[1] = new Array("1-专线","3","1");
subcat[2] = new Array("2-VPN","3","2");
subcat[3] = new Array("3-网吧","3","3");
subcat[4] = new Array("4-小区","3","4");
subcat[5] = new Array("5-语音","3","5");
subcat[6] = new Array("6-E1","3","6");

subcat[7] = new Array("99-所有产品","1","99");
subcat[8] = new Array("1-专线","1","1");
subcat[9] = new Array("2-VPN","1","2");
subcat[10] = new Array("3-网吧","1","3");
subcat[11] = new Array("4-小区","1","4");
subcat[12] = new Array("6-E1","1","6");

subcat[13] = new Array("99-所有产品","2","99");
onecount=14;

othercat[0] = new Array("999-所有","3","999");
othercat[1] = new Array("001-吴小华","3","001");
othercat[2] = new Array("002-周尊华","3","002");
othercat[3] = new Array("003-徐彤","3","003");
othercat[4] = new Array("004-杜承志","3","004");
othercat[5] = new Array("005-钱理","3","005");
othercat[6] = new Array("006-陈拓","3","006");
othercat[7] = new Array("007-魏忠田","3","007");
othercat[8] = new Array("008-严歆","3","008");
othercat[9] = new Array("009-刘亚","3","09");
othercat[10] = new Array("010-刘果","3","010");
othercat[11] = new Array("011-姜波","3","011");
othercat[12] = new Array("012-姜皓","3","012");
othercat[13] = new Array("013-徐静","3","013");
othercat[14] = new Array("014-杨林","3","014");
othercat[15] = new Array("015-殷毅","3","015");
othercat[16] = new Array("016-范卫东","3","016");
othercat[17] = new Array("017-陈莉","3","017");
othercat[18] = new Array("018-于声雷","3","018");
othercat[19] = new Array("019-兰天","3","019");
othercat[20] = new Array("020-卢梅","3","020");
othercat[21] = new Array("021-吴杰","3","021");
othercat[22] = new Array("022-孙米娜","3","022");
othercat[23] = new Array("023-张娅","3","023");
othercat[24] = new Array("024-熊翔","3","024");
othercat[25] = new Array("025-郑华","3","025");
othercat[26] = new Array("026-无","3","026");

othercat[27] = new Array("999-所有","1","999");
othercat[28] = new Array("001-吴小华","1","001");
othercat[29] = new Array("002-周尊华","1","002");
othercat[30] = new Array("003-徐彤","1","003");
othercat[31] = new Array("004-杜承志","1","004");
othercat[32] = new Array("005-钱理","1","005");
othercat[33] = new Array("006-陈拓","1","006");
othercat[34] = new Array("007-魏忠田","1","007");
othercat[35] = new Array("008-严歆","1","008");
othercat[36] = new Array("009-刘亚","1","009");
othercat[37] = new Array("010-刘果","1","010");
othercat[38] = new Array("011-姜波","1","011");
othercat[39] = new Array("012-姜皓","1","012");
othercat[40] = new Array("013-徐静","1","013");
othercat[41] = new Array("014-杨林","1","014");
othercat[42] = new Array("015-殷毅","1","015");
othercat[43] = new Array("016-范卫东","1","016");
othercat[44] = new Array("017-陈莉","1","017");
othercat[45] = new Array("018-于声雷","1","018");
othercat[46] = new Array("019-兰天","1","019");
othercat[47] = new Array("020-卢梅","1","020");
othercat[48] = new Array("021-吴杰","1","021");
othercat[49] = new Array("022-孙米娜","1","022");
othercat[50] = new Array("023-张娅","1","023");
othercat[51] = new Array("024-熊翔","1","024");
othercat[52] = new Array("025-郑华","1","025");
othercat[53] = new Array("026-无","1","026");
othercat[54] = new Array("999-所有","2","999");
onecount1=55
function changelocation(locationid)           '此函数实现菜单连动
{
document.myform.user_type.length = 0;     '将length下标清0
document.myform.sales.length = 0;
var locationid=locationid;
var i;

for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.user_type.options[document.myform.user_type.length]
= new Option(subcat[i][0], subcat[i][2]);    '通过函数传过来的值,定位连动下拉
}                                            '框内容
}




for (i=0;i < onecount1; i++)
{
if (othercat[i][1] == locationid)
{
document.myform.sales.options[document.myform.sales.length]
= new Option(othercat[i][0], othercat[i][2]);
}
}

}
//-->
</script>


<select name="data_or_voice" onChange="changelocation(document.myform.data_or_voice.options
[document.myform.data_or_voice.selectedIndex].value)">
<option value="3" selected>3-全部</option>
<option value="1">1-数据</option>
<option value="2">2-语音</option>
</select>
'下拉框内容变动时,调用changelocation函数

         <select name=user_type>

            <%for i=1 to rs.recordcount%>

            <option value='<%=rs("user_type_id")%>'><%=rs("user_type_2")%></option>
            <%
              rs.movenext
              next
              rs.close
              
              %>            

         </select>
'连动下拉框初始内容

         <select name=sales>

            <%for i=1 to rs.recordcount%>

            <option  value='<%=rs("sales_id")%>'><%=rs("sales_2")%></option>
<%
              rs.movenext
              next
              rs.close
              
              %>            
            
         </select>
'第二个连动下拉框

以上程序实现的是变动一个下拉框内容,另两个下拉框产生联动.然后在其它页面就可以用request来提取相应的值了,整个程序在一个页面内完成.这是我看到下拉菜单连动最简单的方法了.
中间和数据库相联的相关代码我就省略了,.
呼.....从晚上11点开始做,到现在...凌晨2点过了....终于做出来了....实在笨得可以.....时间这么长....不要笑我哈...


回复列表 (共3个回复)

沙发

不错,支持一下

板凳

精神是可佳的![em9]

3 楼

非常感谢!

我来回复

您尚未登录,请登录后再回复。点此登录或注册