ajax多级联动菜单代码及演示 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Nov 24

ajax多级联动菜单代码及演示 不指定

tommyhu , 20:03 , ASP , Comments(0) , Trackbacks(0) , Reads(18394) , Via Original Large | Medium | Small

Highslide JS
演示
带数据库的代码下载,从XML或者数据库里读取数据!
Download ( 1 downloads)
Only registered users can download this file. Please Register or Login



asp数据库版二级联动下拉菜单

<script language = "JavaScript">
subcat=new Array();
<%
Dim i
i=0
set rs2=server.createobject("adodb.recordset")
sqltext="select * from [shopxp_stype]"
rs2.open sqltext,conn,1,1
do while not rs2.eof
%>
subcat[<%=i%>]=new Array("<%=rs2("shopxpse_name")%>","<%=rs2("shopxpbe_id")%>","<%=rs2("shopxpse_id")%>");
<%
i=i+1
rs2.movenext
loop
rs2.close
%>


function changelocation(locationid)
...{
document.myform.shopxpse_id.length = 0;

var locationid=locationid;
var i;
for (i=0;i <subcat.length; i++)
...{
if (subcat[i][1] == locationid)
...{ //这句不是很理解
document.myform.shopxpse_id.options[document.myform.shopxpse_id.length] = new Option(subcat[i][0], subcat[i][2]);
}


}

}

</script>

<body>
<form name="myform" method="post" action="adproductshopxp_do.asp" OnSubmit="return checkkk()" >
<table width="90%" border="0" cellpadding="0" cellspacing="5" bgcolor="#F1F3F5">
<tr >
<td width="30%" align="right">选择商品的分类:</td>
<td width="70%">

大类:
<select name="shopxpbe_id" size="1" id="shopxpbe_id" onChange="changelocation(document.myform.shopxpbe_id.options[document.myform.shopxpbe_id.selectedIndex].value)">
<option selected value="0">请选择大类</option>

<%sql="select shopxpbe_id,shopxpbe_name from shopxp_btype"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof%>
<option value="<%=rs(0)%>"><%=rs(1)%></option>
<%rs.movenext
loop
rs.close%>

</select>
小类:
<select name="shopxpse_id">

<option selected value="0">请选择小类</option>


</select> </td>
</tr>


备注:数据库结构:

shopxp_btype表:shopxpbe_id,shopxpbe_name

shopxp_stype表:shopxpse_id,shopxpse_name,shopxpbe_id


ASP三级联动下拉菜单(调用数据库数据)

-- '数据库结构
'类别1表名称:thatchina_class_1 字段:class1_id,class1_name 说明:class1_id为主键是类别1的ID值,class1_name为类别1的名称
'类别2表名称:thatchina_class_2 字段:class2_id,belongto_class1,class2_name 说明:class2_id为主键是类别2的ID值,belongto_class1为所属类别1的ID值,classs2_name为类别2的名称
'类别3表名称:thatchina_class_3 字段:class3_id,belongto_class1,belongto_class2,class3_name说明:class3_id为主键是类别3的ID值,belongto_class1为所属类别1的ID值,belongto_class2为所属类别2的ID值,class3_name为类别3的名称


<%
Set conn = Server.CreateObject("ADODB.Connection")
strsql="PROVIDER=SQLOLEDB;DATA SOURCE=数据库IP;UID=数据库id;PWD=lg5816081;DATABASE=数据库名"
conn.Open strsql
%>

%>
<!-- 三级联动菜单 开始 -->
<script language="JavaScript">
<!--
<%
Dim count2,rsClass2,sqlClass2
set rsClass2=server.createobject("adodb.recordset")
sqlClass2="select * from thatchina_class_2"
rsClass2.open sqlClass2,conn,1,1
%>
var subval2 = new Array();
<%
count2 = 0
do while not rsClass2.eof
%>
subval2[<%=count2%>] = new Array('<%=rsClass2("belongto_class1")%>','<%=rsClass2("class2_id")%>','<%=rsClass2("class2_name")%>')
<%
count2 = count2 + 1
rsClass2.movenext
loop
rsClass2.close
%>

<%

Dim count3,rsClass3,sqlClass3
set rsClass3=server.createobject("adodb.recordset")
sqlClass3="select * from thatchina_class_3"
rsClass3.open sqlClass3,conn,1,1
%>
var subval3 = new Array();
//数组结构:二级根值,三级根值,三级显示值
<%
count3 = 0
do while not rsClass3.eof
%>
subval3[<%=count3%>] = new Array('<%=rsClass3("belongto_class2")%>','<%=rsClass3("class3_id")%>','<%=rsClass3("class3_name")%>')
<%
count3 = count3 + 1
rsClass3.movenext
loop
rsClass3.close
%>

function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==请选择类别==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择专题==','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}

function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择专题==','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>

<form name="form1" method="post" action="test1.asp">

三级联动:
<%
Dim count1,rsClass1,sqlClass1
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from thatchina_class_1"
rsClass1.open sqlClass1,conn,1,1
%>
<select name="s1" onChange="changeselect1(this.value)">
<option>==请选择频道==</option>
<%
count1 = 0
do while not rsClass1.eof
response.write"<option value="&rsClass1("class1_id")&">"&rsClass1("class1_name")&"</option>"
count1 = count1 + 1
rsClass1.movenext
loop
rsClass1.close
%>
</select>

<select name="s2" onChange="changeselect2(this.value)">
<option>==请选择类别==</option>
</select>

<select name="s3">
<option>==请选择专题==</option>
</select>
<input type="submit" name="Submit" value="提交"></form>


网上用的比较多的asp级联菜单效果代码

<!--#include file="inc/conn.asp"-->    
<%
function   DbCombox()
    dim   rs,sql,msg
    sql   =   "select * from class1 order by paixu desc"
    set   rs   =   conn.execute(sql)
    while   not   rs.eof
      msg   =   msg   &   "<option   value="""   &   rs("id")   &   """>"   &   rs("class1")   &   "</option>"
      rs.movenext
    wend
    rs.close
    set   rs   =   nothing
    DbCombox   =   msg
End   function
%>
<html>
  
<head>
<meta   http-equiv="Content-Language"   content="zh-cn">
<meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">
<title>会员登录</title>
</head>
  
<body>
<script   language   ="javascript"   >
Citys   =   new   Array();
<%

sql   =   "select * from class2   order by paixu desc"
set   rs   =   Conn.execute(sql)
i   =   0
while   not   rs.eof
%>
Citys[<%=i%>]   =new   Array("<%=rs("class1")%>","<%=rs("class2")%>");
<%
i   =   i   +   1
rs.movenext
wend
rs.close
set   rs   =   nothing
%>
  
function   changeselect(selvalue){
    var   selvalue   =   selvalue;
    var   i;
    document.form1.City.length   =   0   ;
    document.form1.City.options[document.form1.City.length]   =   new   Option("请选择","");
    for   (i   =   0   ;i   <Citys.length;i++){
      if(Citys[i][0]==selvalue){
        document.form1.City.options[document.form1.City   .length]   =   new   Option(Citys[i][1],Citys[i][1]);
      }
    }
}
  
document.form1.City.options[document.form1.City.length]   =   new   Option("请选择","");
  
</script>
  
              <div   align="center">
                  <form   method="POST"   action="forum.asp"   name="form1">
                      <table   border="0"   cellpadding="0"   style="border-collapse:   collapse"   width="100%"   id="table1"   height="59">
                          <tr>
                              <td   width="67"   height="30"   bgcolor="#D4D0C8"><b><font   size="2">地区</font></b></td>
                              <td   height="30"   bgcolor="#D4D0C8"><select   size="1"   name="Region"   onchange   ="changeselect(document.form1.Region.options[document.form1.Region.selectedIndex].value)">
                              <%=DbCombox()%></select></td>
                          </tr>
                          <tr>
                              <td   width="67"   height="30"><b><font   size="2">城市</font></b></td>
                              <td   height="30"><select   size="1"   name="City"></select></td>
                          </tr>
                          </table>
                  </form>
              </div>
  
</body>
  
</html>
Pages: [1] [2] [3]

▲返回顶部
Last modified by tommyhu on2009/12/30 20:34

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot