通行证: 用户 密码 域名空间  下载中心 社区论坛 信息公告 MY小屋
联系我们
设为首页
加入收藏

 

QQ,ASP,PHP,JSP,XML,SQL,.Net,编程 程序 网页图象 建站经验 私服
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿
论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图
专题 | 应用软件 | 聊天通讯 | Q Q 专栏 | 建站经验 | 在线工具 | 站长Club | 注 册 表 | 旧版
社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 韩国素材 | 素材图库 | 广告服务 | 服务
当前位置:首页>>编程开发>>asp专区>>正文 新版上线![旧版]
注:打开慢时请稍等

建立动态下拉式选单(三阶层)

http://www.iyit.net  日期:2006-6-7 10:50:22  来源:不详  点击:
参加讨论】   '建立動態下拉式選單 (三階層)

<%'将资料库连结字串, 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++)" & vbcrlftempSTR =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]);" & vbcrlftempSTR =tempSTR & "}" & vbcrlf
tempSTR =tempSTR & "document." & myForm & "." & listname3
tempSTR =tempSTR & ".length=key1[document.myForm.color.selectedIndex][num].length;" & vbcrlftempSTR =tempSTR & "}" & vbcrlf
myfun=tempSTR
END sub
%>  

编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:用ASP编写的“俄罗斯方块游戏”
下一篇:无组件文件上传代码实例
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

 相关文章
最新更新 热点排行 推荐新闻
ASP初学者常犯的几个错误
rs.open sql,conn,1,1全接触
处理较长文章,添加 …… 效果
[ASP]利用 xmlhttp 分块上传文件
asp,php 和 jsp 比较 之我见
ncsc
重庆大学生引资百万建网站半年倒闭
PHP安装攻略:安装并配置PHP
PHP应用分页显示制作详细讲解
MySQL数据库基础教程
Php利用java解析xml
使用PHP实现动态网页
使用PHP和XSL stylesheets转换XML文档
在php中输出html代码
关于session的问题集锦解决方案
用ASP+XMLHTTP编写天气预报程序
ASP如何获取真实IP地址
VS .net 2003调试javascript中两个杂症
datagrid编辑、修改、删除、翻页例子
rs.open sql,conn,1,1全接触
QQ密码本地破解
msn8.0下载
珊蝴虫QQ探测隐身的招式用法
Visual Basic 概述
exeplorer.exe错误的问题的总结、解决
解决Windows中的explorer.exe出错
Authorware7.0基础与实例教程连载 第5
PPLive最新内部版本揭密
Windows常见文件修复技巧
一个好汉N个帮 Word实用插件集锦
ASP 五大高效提速技巧
ASP中使用SQL语句教程
测试一下喽!
Windows下的虚拟主机设置全功略
危险无处不在 Html标签带来的安全隐患
网络游戏是06年互联网最具发展潜力业务
巧用ACDSee 8.0截取QQ表情每一帧
解除瑞星 诺顿遗留下的杀毒兼容问题
第一款开源AJAX安全扫描工具Sprajax
WinRAR人性化功能揭密
在ASP.NET中防止注入攻击
用ASP.NET开发Web服务的五则技巧
Linux操作系统12则经典应用技巧
 友情链接
设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyrights © 2004-2006 iYiT.Net All Rights Reserved.
网站合作、广告联系QQ:147007642、466949678
易特网络技术 点击这里给我发消息