asp两级联动代码怎么写

我现在需要两级联动~划红线的是一级请大牛们帮帮忙~急用啊... 我现在需要两级联动~划红线的是一级 请大牛们帮帮忙~急用啊 展开
 我来答
清风之无痕岁月05
2013-08-04 · TA获得超过236个赞
知道小有建树答主
回答量:487
采纳率:77%
帮助的人:137万
展开全部
分类表格设置字段: ID, name ,parID ;ID为关键字自动增加 ,name是分类名称,parID是记录这个分类名称的父类ID设置默认值为0,为0表示为顶级.
用2个记录集循环出对应的记录

效果地址
http://kartty.com/ProdType.asp
别改动啊.....

前台
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
On Error Resume Next
response.Charset="utf-8"
dim conn,sql,rs,pormpt
set conn = server.CreateObject("ADODB.Connection")
conn.open (application("conn"))
sql="select id,name,parid from class ORDER BY name asc"

set rs=conn.execute(sql)

do while not rs.eof
if jsarr<>"" then
jsarr= jsarr&",new Array('"&rs("id")&"','"&rs("name")&"','"&rs("parid")&"')"
else
jsarr="new Array('"&rs("id")&"','"&rs("name")&"','"&rs("parid")&"')"
end if
rs.MoveNext
loop

prompt=request.Cookies("prompt")
response.Cookies("prompt")=""
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product Type</title>
<style type="text/css">
*{ margin:0px; padding:0px;}

</style>
<script type="text/javascript" language="javascript1.5">
var ppt="<%=prompt %>";
if(ppt!=""){
alert(unescape(ppt));

}

//用ASP循环出类型的多维数组
//首先创建1个二维数组
//数组的第一维的每个元素存储的都是一个子数组,且每个子数组中都有3个元素,分别表示列表菜单的value值,显示文本(对应ASP数据库中的ID,name),还有一个显示父级ID
//其中顶级类别的父元素为空或0等自己设定,如:list[0]=new Arrary("ID值","显示text","父级ID");
var listArray=new Array(<%= jsarr %>);
//listArray[listArray.length]=new Array("1","一级菜单1","-1");
//listArray[listArray.length]=new Array("1","一级1菜单",0);
//listArray[listArray.length]=new Array("11","二级1子菜单1","1");
//listArray[listArray.length]=new Array("12","二级1子菜单2","1");
//listArray[listArray.length]=new Array("13","二级1子菜单3","1");
//
//listArray[listArray.length]=new Array("2","一级2菜单",0);
//listArray[listArray.length]=new Array("21","二级2子菜单1","2");
//listArray[listArray.length]=new Array("22","二级2子菜单2","2");
//listArray[listArray.length]=new Array("23","二级2子菜单3","2");
//
//
//listArray[listArray.length]=new Array("231","三级2子菜单1","21");
//listArray[listArray.length]=new Array("232","三级2子菜单2","21");
//listArray[listArray.length]=new Array("233","三级2子菜单3","21");
function listMeun(parid,chiid){
if(parid==""){
var parvalue=0;
}else{
document.getElementById((chiid+"1")).style.display="none"
var par=document.getElementById(parid)
//获取现在选择的项
var parvalue=par.options[par.selectedIndex].value;

// for(i=0;i<par.length;i++){
// if(par.options[i].selected==true){
// var parvalue=par.options[i].value;
// break;
// }

}
var chi=document.getElementById(chiid);
//每次选择符列表项时,都要初始化对应的子项,详情请查看W3C options属性
chi.options.length=1;

for(i=0;i<listArray.length;i++){
if(listArray[i][2]==parvalue){
chi.add(new Option(listArray[i][1],listArray[i][0]));
}
}
//alert(par)
if(parvalue!=0){
if(chi.options.length>1){
document.getElementById((chiid+"1")).style.display=""
}
}
}

//辅助函数;查看每次选择项 的文本和值,用于确认是否设置正确,
function view(e){
document.getElementById("show").innerText="显示:"+e.options[e.selectedIndex].text+" ---值:"+e.options[e.selectedIndex].value;

// for(i=0;i<e.length;i++){
// if(e.options[i].selected==true){
// document.getElementById("show").innerText="显示:"+e.options[i].text+" ---值:"+e.options[i].value;
// break;
// }
// }
}

</script>
</head>

<body onload="listMeun('','oneselect')">

<form action="./ProdTypeba.asp" method="post" enctype="application/x-www-form-urlencoded" name="form1" target="_self" id="form1">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="49" height="32"> </td>
<td width="107" height="32">Add Category:</td>
<td width="172" height="32">
<input name="genre" type="text" id="genre" /></td>
<td width="102"><font style=" font-size:18px; color:#FF0000; font-weight:900;">※√</font></td>
<td width="70"><a href="ProdType.asp">刷新</a></td>
</tr>
<tr>
<td height="32"> </td>
<td height="32">Parent class:</td>
<td height="32" colspan="3">
<select name="oneselect" id="oneselect" onchange="listMeun('oneselect','twoselect') ">
<option value="0" selected="selected">请选择</option>
</select>
<samp id="twoselect1" style="display:none"> </samp>
<select name="twoselect" id="twoselect" >
<option value="0" selected="selected">请选择</option>
</select>
<label>
<input name="submit2" type="button" id="submit2" value="two" onclick="view(document.getElementById('twoselect'))"/>
<input name="submit22" type="button" id="submit22" value="one" onclick="view(document.getElementById('oneselect'))"/>
</label></td>
</tr>
<tr>
<td height="32" align="center"> </td>
<td height="32" colspan="4" align="left">
<input name="submit" type="submit" id="submit" value="ALT" />

<input name="submit" type="submit" id="submit" value="DEL" />
<input name="submit" type="submit" id="submit" value="ADD" /></td>
</tr>
</table>
</form>
<div id="show"></div>
</body>
</html>

后台
'生成1级2级分类Child.js文件和Parent.inc文件
set rs=conn.execute("select id,name from class where parid=0")
parstr="<ul>"
do while not rs.eof
parstr=parstr&"<li style='width:190px;line-height:32px;'>"&vbCrLf&"<a id='"&rs("name")&"' href='./Product.asp?id="&rs("id")&"' onmouseout='menu(this.id,""chiid"",1);' onmouseover='menu(this.id,""chiid"",0,"&rs("name")&");' >"&rs("name")&"</a>"&vbCrLf&"</li>"&vbCrLf
set chirs=conn.execute("select id,name from class where parid="&rs("id"))
chistr=chistr& "var "&rs("name")&"=""<ul>"
do while not chirs.eof
chistr=chistr& "<li><a href='./Product.asp?id="&chirs("id")&"'>"&LCase(chirs("name"))&"</a></li>"
chirs.movenext
loop
chistr=chistr&"</ul>"";"&vbCrLf
chirs.Close
rs.movenext
loop
set chirs=nothing
zmspu1
2013-08-04 · TA获得超过289个赞
知道小有建树答主
回答量:1425
采纳率:100%
帮助的人:963万
展开全部
数据库设计的时候不好,所以影响了你现在的编程。最好是改下数据库:加入level,或者一type这样的字段,用来表示所属于哪个菜单级。
如果已经不能改了,按现在的结构也可以,就是需要判断一下:

一级:select * from 表 where len(menu)=6
二级:select * from 表 where left(menu,6)="一级的值" and len(menu)>6

当然,其他方法也很多的,这里只是写一个简单的示例。
我个人建议最好还是改下数据结构更好
追问
我要的联动代码~下列表的联动代码
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友7019904
2013-08-05 · 超过18用户采纳过TA的回答
知道答主
回答量:37
采纳率:0%
帮助的人:46.5万
展开全部
代码写出来就太长了,可以给个思路你。先读取一级数据加载在一级下拉列表,然后根据在下拉列表select的onchange()事件里判断所选取的值再加载二级数据,简单点用表单提交的方法可实现,也可用ajax实现无刷新实时加载
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式