作如下的三个下拉菜单,第一个菜单内容从数据库的一个表中读出,当选择后第二个菜单内容按第一个的结果为条件从另表中读出,第三个菜单内容按第一、第二选择的条件从表中读出。

johns 2001-09-13 05:51:17
...全文
318 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
whatme168 2001-09-25
  • 打赏
  • 举报
回复
上面的兄弟,这样可以吗 我也正遇上同样的问题,能帮小弟一把吗??
rockytan 2001-09-19
  • 打赏
  • 举报
回复
ok
wang_shine 2001-09-18
  • 打赏
  • 举报
回复
以上应该是jones要的,你做一下吧
wang_shine 2001-09-18
  • 打赏
  • 举报
回复
对不起,rockytan(rockytan),这两天出差了,没有及时回复:
1,我举个例子吧,父类和子类在一个表中
fatherid,childrenid,description 要实现我给你说的联接要求
2, 给页面两个列表框,给出id,如first,second,放在form1中
一个显示父亲类(要在读页面是就显示,asp可以做到,不重复)
3,在页面里包含文件
<SCRIPT LANGUAGE="JavaScript" src="../../_ScriptLibrary/RS.HTM"></script>
<SCRIPT LANGUAGE="JavaScript">RSEnableRemoteScripting("../../_ScriptLibrary")</SCRIPT>
这两个文件其实就是iis创建时的library,注意你的路径,没有的话考一份
4,客户端脚本
function first_onchange()
{
var first_select;
form1.second.innerHTML="";
first_select=form1.first.value;
context = "squaring";
co=RSExecute("getcat.asp","add",first_select);//这句话是调用服务器端的程序的,注意路径
result=co.return_value;//得到服务器传回结果
var option,value,list_array,result,i,;
list_array=result.split("/");
i=0;
form1.second.innerHTML=""; //列表框内清除
//下面就要把 result 进行处理了,假定处理后放在数组list_array[i]里(以 childid,description,childid,description,...存放)
//现在得到list_array[i],要放到 second 列表框中

//
while (list_array[i]!="*")
{
if (list_array[i]!="")
{
if (i%2==1) //奇数项是 description
{
bb.text=list_array[i];
form1.second.add (bb);
}
else
{
bb=document.createElement ("OPTION");////偶数项是 childid

bb.value=list_array[i];
}

}
i=i+1;
} {
bb=document.createElement ("OPTION");
bb.value=list_array[i];

}


服务端程序:
<%@Language=VBScript%>
<%RSDispatch %>//必需的
<!--@CopyWright&Edit by Wang xuejun April,2001--〉
<!--'please pay attention to the path of the folder _scriptlibrary,it should be included in. -->

<!--#INCLUDE FILE="../../_ScriptLibrary/RS.ASP"-->//同客户端
<SCRIPT RUNAT=SERVER LANGUAGE="JavaScript">
var public_description = new MyServerMethods();
function MyServerMethods()
{
this.add = Function( 'value','return add(value)' );//用java声明指向vbscript 函数
}
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE="VBScript">
Function add(value)//value是传过来的父亲id
dim second,value1,value2
second=""
//下面是从表中根据得到的父类id 把子类找出来
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "cxxxx"
Set Rs= Server.CreateObject("ADODB.Recordset")
sqlText="select childid,description from table where fatherid="&value
Rs.open sqlText,conn,1
while not Rs.eof
second=second&Rs("childid")&"/"&Rs("description")&"/"
Rs.movenext
wend
rs.Close
conn.Close
set rs=nothing
set conn=nothing
add=second&"*"//用*表明数组完毕
End Function
</SCRIPT>


oK!终于完了,挺费尽的吧,你试着做一下
rockytan 2001-09-17
  • 打赏
  • 举报
回复
好是好,但就是难实现啊,还是用简单的方法吧,让它自己挑
zhu_joe 2001-09-16
  • 打赏
  • 举报
回复
我同意“我只是觉得三个列表的对应项规则定义好,处理起来好方便的啊!!”
这样吧数据库表中拥代码 XX,XX,XX 表示具体的一个小类,前面的XX,XX表示中类,
最前面XX表示大类,这样就可以很方便的处理了,有了三张代码表,以后的处理也会变得
相当方便。
hope2002 2001-09-15
  • 打赏
  • 举报
回复
如果机器上有安装MSDN去查一下Tabular Data Control(TDC)控件的用法吧,可以解决你这个问题!
S.F. 2001-09-15
  • 打赏
  • 举报
回复
我只是觉得三个列表的对应项规则定义好,处理起来好方便的啊!!
flyingghost 2001-09-15
  • 打赏
  • 举报
回复
把所有的爸爸儿子孙子读出来,放在JavaScript的数组里,再用onchange事件和JavaScript来控制。行不行?
关注。
johns 2001-09-14
  • 打赏
  • 举报
回复
这个例子是不错,但和我的情况有些区别,我现在要做的是:有两个表,一个是kwname,里面有id和name两个字段,一个是baokan,里面有id\name\cbdate\ban四个字段,我先从kwname表中读出name,作为第一个菜单的内容,然后从表baokan中按第一个菜单选择的name读出cbdate作为第二个菜单的内容,接着根据前两个菜单的选择在baokan表中读出ban 作为第三个菜单的内容。
kenspc 2001-09-14
  • 打赏
  • 举报
回复
这里有个范例,看一下(原出处:http://www.pc-net.com.tw/aspro/article/asp0521.asp?articleid=50)

<%'将资料库连结字串, SQL 叙述,形成第一个表单字串变数 (colorlist),第一个表单名称
'color,形成第二个表单字串变数 (fruitlist),第二一个表单名称 fruit,形成第三个表单字串变数
'(pricelist),第三个表单名称 price,等资讯透过呼叫副程式的方式经过处理之后再传回主程式
'中,请注意有某几个参数是以 ByRef 的方式传回主程式,而某些参数是以 ByVal 的方式传回
'的紫色粗体字代表是 ByRef。请直接观看底下副程式的部分
myDSN="Provider=SQLOLEDB; Data Source=Jackal; Initial Catalog=pubs; User ID=sa; Password="
strSQL="select color.color, fruit.fruit, price.cost from color join fruit on color.ID=fruit.COLORID join price on price.FRUITID=fruit.ID order by color.ID"
call listmaker(myDSN, strSQL, colorlist,"color", fruitlist ,"fruit", pricelist, "price", pubevent, pubfun, "myForm")
%><form name="myForm" method=post action=listbox2.asp>
颜色:
<%= colorlist%>

<BR>
水果:


<%= fruitlist%>

<BR>
价格:
<%= pricelist%>
<input type=submit value="送出">
</Form>
<SCRIPT Language="JavaScript"><!--

<%=pubevent%>
<%=pubfun%>
--></Script>


<%

SUB listmaker(myDSN, strSQL,byref list1, listname1, byref list2, listname2, byref list3, listname3, byref myevent, byref myfun, myForm)

Set my_conn = Server.CreateObject("ADODB.Connection")
my_conn.open myDSN
set rs=my_conn.execute(strSQL)
'利用 colorlist 字串变数来建立第一个下拉式选单的 Html 原始码。
colorlist="<select name=" & listname1
colorlist=colorlist & " OnChange=""Buildkey"
colorlist=colorlist & "(this.selectedIndex);"">"
'利用 fruitlist 字串变数来建立第二个下拉式选单的 Html 原始码。
fruitlist="<select name=" & listname2
fruitlist=fruitlist & " OnChange=""Buildkey1"
fruitlist=fruitlist & "(this.selectedIndex);"">"
'利用 pricelist 字串变数来建立第三个下拉式选单的 Html 原始码。
pricelist="<select name=" & listname3 & ">"
'在这里初始某些变数值,当作底下执行运算时之旗标值。
loopcounter=0
lastvalue=rs(0)
lastvalue2=rs(1)
redim tempArray(1)
'thisgroupcount 代表某种颜色共有几种水果
thisgroupcount=0
'thissubgroupcount 代表某种水果共有几种价格,当水果变换时 thissubgroupcount 会归零,并重新
'累加。
thissubgroupcount=0
'howmanygroups 代表共有几种颜色
howmanygroups=0
'howmanysubgroups 代表共有几种水果,当颜色变换时 howmanysubgroups 会归零,并重新
'累加。
howmanysubgroups=0
DO UNTIL rs.eof
thisvalue=rs(0)
thisvalue2=rs(1)
thisvalue3=rs(2)

'如果发现水果名称改变,而且目前水果是某种颜色的第一种水果时,譬如:红色←苹果
'或:黄色←柳丁时就在 Script 中加上颜色标记 (为了让大家更容易将 Script 区隔开
'来),然后再将水果名称定义到 key 阵列值,
'接着再定义 key1[第几种颜色][第几种水果] 之阵列长度。

if thisvalue2<>lastvalue2 then
If howmanysubgroups=0 then
tempSTR1=tempSTR1 & "// " & lastvalue & vbcrlf
tempSTR2=tempSTR2 & "// " & lastvalue & vbcrlf
end If
tempSTR2=tempSTR2 & "key1[" & howmanygroups & "][" & howmanysubgroups &
"]=new Array(" & thissubgroupcount & ");" & vbcrlf
tempSTR1=tempSTR1 & "key[" & howmanygroups & "][" & howmanysubgroups &
"]=""" & lastvalue2 & """;" & vbCRLF
howmanysubgroups=howmanysubgroups+1
thissubgroupcount=0
lastvalue2=thisvalue2
end if
'执行结果如下
// 红色
key[0][0]="苹果";
key[0][1]="莲雾";
key[0][2]="李子";
// 黄色
key[1][0]="柳丁";
key[1][1]="葡萄柚";
// 绿色
key[2][0]="芭乐";
key[2][1]="西瓜";
key[2][2]="枣子";
// 红色
key1[0][0]=new Array(3);
key1[0][1]=new Array(3);
key1[0][2]=new Array(3);
// 黄色
key1[1][0]=new Array(3);
key1[1][1]=new Array(3);
// 绿色
key1[2][0]=new Array(3);
key1[2][1]=new Array(3);
key1[2][2]=new Array(3);

'如果发现颜色名称改变,就定义 key[第几种颜色] 阵列值,
'接着再定义 key1[第几种颜色] 之阵列长度,重复定义的原因在之前已跟大家说过了,然
'后将howmanygroups (颜色种类) 值加一,并将水果种类计数值 (thisgroupcount) 归零
if thisvalue<>lastvalue then
tempSTR=tempSTR & "key[" & howmanygroups & "]=new Array(" & howmanysubgroups & ");" & _
vbcrlf
tempSTR=tempSTR & "key1[" & howmanygroups & "]=new Array(" & howmanysubgroups & ");" & _
vbcrlf
thisgroupcount=0
howmanygroups=howmanygroups+1
howmanysubgroups=0
end if

'执行结果如下
key=new Array(3);
key1=new Array(3);
key[0]=new Array(3);
key1[0]=new Array(3);
key[1]=new Array(2);
key1[1]=new Array(2);
key[2]=new Array(3);
key1[2]=new Array(3)
'如果 thisgroupcount=0 代表目前颜色改变,此时将颜色名称写到 color 下拉式选单中
if thisgroupcount=0 then
colorlist =colorlist & "<option>" & thisvalue & "</option>" & vbcrlf
end if
'如果 thissubgroupcount=0 代表目前水果改变,此时在key1[第几种颜色][第几种水果][第几
'种价格] 阵列值前加上水果名称标记,让大家更容易将水果名称与价格区隔开来。
if thissubgroupcount=0 then
tempSTR3=tempSTR3 & "// " & lastvalue2 & vbcrlf
end if
'定义key1[第几种颜色][第几种水果][第几种价格] 阵列值。
tempSTR3=TempSTR3 & "key1[" & howmanygroups & "][" & howmanysubgroups & "][" & thissubgroupcount & "]=""" & thisvalue3 & """;" & vbCRLF
'执行结果:
// 频果
key1[0][0][0]="10元";
key1[0][0][1]="20元";
key1[0][0][2]="30元";
// 莲雾
key1[0][1][0]="40元";
key1[0][1][1]="50元";
key1[0][1][2]="60元";
// 李子
key1[0][2][0]="70元";
key1[0][2][1]="80元";
key1[0][2][2]="90元";
// 柳丁
key1[1][0][0]="100元";
key1[1][0][1]="110元";
key1[1][0][2]="120元";
// 葡萄柚
key1[1][1][0]="130元";
key1[1][1][1]="140元";
key1[1][1][2]="150元";
// 芭乐
key1[2][0][0]="160元";
key1[2][0][1]="170元";
key1[2][0][2]="180元";
// 西瓜
key1[2][1][0]="190元";
key1[2][1][1]="200元";
key1[2][1][2]="210元";
// 枣子
key1[2][2][0]="220元";
key1[2][2][1]="230元";
key1[2][2][2]="240元";

'如果目前是第一种颜色,而且水果名称正在改变,就将水果名称写到 fruit 下拉式选单中
if howmanygroups=0 then
If thissubgroupcount=0 then
fruitlist = fruitlist & "<option>" & thisvalue2 & "</option>" & vbcrlf
end if
End If

'如果目前是第一种颜色,而且是第一种水果,就将价格写到 price 下拉式选单。
if howmanygroups=0 then
if howmanysubgroups=0 then
pricelist = pricelist & "<option>" & thisvalue3 & "</option>" & vbcrlf
end if
End if

thisgroupcount=thisgroupcount+1
thissubgroupcount=thissubgroupcount+1
lastvalue=thisvalue
loopcounter=loopcounter+1
rs.movenext

LOOP
'别忘了最后一个 key[第几种颜色] 和 key1[第几种颜色] 的阵列长度还未定义。
tempSTR=tempSTR & "key[" & howmanygroups & _
"]=new Array(" & howmanysubgroups+1 & ");" & _
vbcrlf
tempSTR=tempSTR & "key1[" & howmanygroups & _
"]=new Array(" & howmanysubgroups+1 & ");" & _
vbcrlf

'别忘了最后一个 key[第几种颜色][第几种水果] 和 key1[第几种颜色][第几种水果] 的阵列长
'度还未定义。
tempSTR2=TempSTR2 &"key1[" & howmanygroups & "][" & howmanysubgroups & "]=new Array(" & thissubgroupcount & ");" & _
vbcrlf
tempSTR1= TempSTR1 & "key[" & howmanygroups & "][" & howmanysubgroups & "]=""" & lastvalue2 & """;" & vbCRLF
tempSTR=tempSTR & TempSTR1 & TempSTR2 & tempSTR3
'将 color 下拉式选单作一个结尾
colorlist=colorlist & "</select>"
'将 fruit 下拉式选单作一个结尾
fruitlist= fruitlist & "</select>"
'将 price 下拉式选单作一个结尾
pricelist= pricelist & "</select>"

'一开始的 key 和 key1 阵列也不要忘记定义了。

myevent=vbcrlf & "key=new Array(" & howmanygroups+1 & ");"
myevent=myevent & vbcrlf & "key1=new Array(" & howmanygroups+1
myevent=myevent & ");" & vbcrlf & tempSTR

'大功告成,可以关闭资料库了。
rs.close
set rs=nothing
my_conn.close
set my_conn=nothing

'先产生 Buildkey 副程式,这边一点都不困难,原理在上面已经解释过了,笔者不再赘述,执行结果为:
function Buildkey(num)
{
Buildkey1(0);
document.myForm.fruit.selectedIndex=0;
for(ctr=0;ctr<key[num].length;ctr++)
{
document.myForm.fruit.options[ctr]=new Option(key[num][ctr],key[num][ctr]);
}
document.myForm.fruit.length=key[num].length;
}

tempSTR =vbcrlf & "function Buildkey" & "(num)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "Buildkey1(0);" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "."
tempSTR =tempSTR & listname2 & ".selectedIndex=0;" & vbcrlf
tempSTR =tempSTR & "for(ctr=0;ctr<key[num].length;ctr++)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myform & "." & listname2
tempSTR =tempSTR & ".options[ctr]=new Option(key[num][ctr],"
tempSTR =tempSTR & "key[num][ctr]);" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "." & listname2
tempSTR =tempSTR & ".length=key[num].length;" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf

'再产生 Buildkey1 副程式
function Buildkey1(num)
{
document.myForm.price.selectedIndex=0;
for(ctr=0;ctr<key1[document.myForm.color.selectedIndex][num].length;ctr++)
{
document.myForm.price.options[ctr]=new Option(key1[document.myForm.color.selectedIndex][num][ctr],key1[document.myForm.color.selectedIndex][num][ctr]);
}
document.myForm.price.length=key1[document.myForm.color.selectedIndex][num].length;
}

tempSTR =tempSTR & vbcrlf & "function Buildkey1" & "(num)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "."
tempSTR =tempSTR & listname3 & ".selectedIndex=0;" & vbcrlf
tempSTR =tempSTR & "for(ctr=0;ctr<key1[document.myForm.color.selectedIndex][num].length;ctr++)" & vbcrlf
tempSTR =tempSTR & "{" & vbcrlf
tempSTR =tempSTR & "document." & myform & "." & listname3
tempSTR =tempSTR & ".options[ctr]=new Option(key1[document.myForm.color.selectedIndex][num][ctr],"
tempSTR =tempSTR & "key1[document.myForm.color.selectedIndex][num][ctr]);" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "." & listname3
tempSTR =tempSTR & ".length=key1[document.myForm.color.selectedIndex][num].length;" & vbcrlf
tempSTR =tempSTR & "}" & vbcrlf
myfun=tempSTR
END sub
%>
johns 2001-09-14
  • 打赏
  • 举报
回复
up
rockytan 2001-09-14
  • 打赏
  • 举报
回复
你说什么费话!
johns 2001-09-14
  • 打赏
  • 举报
回复
S.F. 2001-09-14
  • 打赏
  • 举报
回复
哦,补充补充,小媳妇列表也可以加进去的...至于一对多或者一对一你自己看着办吧...
S.F. 2001-09-14
  • 打赏
  • 举报
回复
你的意思是说三个列表连动吗?而第一列表为爸爸的,第二列表为儿子,第三列表为孙子?
来来,我理解一下,是不是这样...

首先我们只能选择一个爸爸...而这个爸爸是上帝从爸爸表中取出来的一些爸爸中挑选出来组合成的列表的默认项目

而一个爸爸可以有多个儿子,而多个儿子都叫他爸爸..那么就有一个是大儿子,二儿子...N 儿子..大儿子就做列表二的老大....

ok,孙子列表...我们还是按规则来...孙子列表中也分大孙子,小孙子的,大孙子是默认项..而大孙子又分为大儿子.大孙子..大儿子.中孙子..大儿子.小孙子.....

ok,思路清晰了吧 ...
johns 2001-09-14
  • 打赏
  • 举报
回复
差不多,但里面有一些我还是不明白,我刚开始做asp,能说得更详细些吗,最好能按我上面的数据写一下代码,分不够我会加的,请各位高手帮个忙!
wang_shine 2001-09-14
  • 打赏
  • 举报
回复
给你一个连接,看是不是这种效果:
http://www.china-barter.com/barterplat/hyzc/hyzc.asp
johns 2001-09-14
  • 打赏
  • 举报
回复
up
viking 2001-09-13
  • 打赏
  • 举报
回复


做是可以做出来,但是每次菜单变得时候都要提交一次,接受一下变量才行呢!

记着又一种对象可以,跟 RDS 比较接近的一种,把客户端的脚本和数据库联系起来了。

你先用前一种试试吧!

28,405

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧