针对有网友说看不见文章内容, 现提示如下: 点击每一个标题行任一地方都会展开和隐藏此文章内容(不要点击标题). 目前展开隐藏功能只支持IE浏览器,虽然可以改成支持FF浏览器,不过现在一直没时间去弄,等有时间再修改了。 |
blog名称:乱闪Blog 日志总数:267 评论数量:1618 留言数量:-26 访问次数:2669441 建立时间:2005年1月1日 |
|

| |
ASP+JavaScript+数据库 级联下拉菜单
|
<!--***********************************ASP+JavaScript+数据库 级联下拉菜单*********************************** ****演示地址:http://www.jjst.com.cn/test/test.asp **** 以前都用JS的多级级联下拉菜单,但那个有局限性,每次更新列表项内容时都必须修改程序,今天有空,写了这个数据库形式的,易于管理和修改,且你可以在此思路上建立更多级的级联菜单。 好了,废话少说,言归正传。 测试数据库:test.mdb 你可以自己建一个。 ----------------------------------------------------------------------------- 表名: 字段1 字段2 字段3 ----------------------------------------------------------------------------- 表1: big_class big_class_id big_class_name 表2: small_class small_class_id small_class_name belongto_big_class 数据类型 自动编号 文本 数字 ----------------------------------------------------------------------------- 以下是程序清单,共1个文件,文件名:test.asp--><%'option explicitdim conn,connstr,dbdb="test.mdb" '测试数据库Set conn = Server.CreateObject("ADODB.Connection")connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")conn.Open connstr%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>ASP+JavaScript+数据库 级联下拉菜单</title><style>table{border: #00215a 1px dashed;}td{font-size:12px;}input,select{ font-size:9pt; border-style:solid; border-width:1; cursor:default; color:#03326B; background-color:#FFFFFF; height:16px;}a:link,a:visited{color: #000000;text-decoration: none;}a:hover {color: #ff0000;text-decoration: none;FILTER: glow(color=ffffff,strength=0) shadow(color=aaaaaa,direction:135); POSITION: relative; WIDTH: 100%;}</style><script language="JavaScript">function addbig(){document.all.a.style.display="block";document.all.b.style.display="none";document.all.c.style.display="none";}function addsmall(){document.all.b.style.display="block";document.all.a.style.display="none";document.all.c.style.display="none";}function viewmenu(){document.all.a.style.display="none";document.all.b.style.display="none";document.all.c.style.display="block";}</script><%'从小类表中取出数据 set rs=server.CreateObject("adodb.recordset") sql="select * from small_class " rs.open sql,conn,1,1%><script language="JavaScript">var num;//定义数组var calArray=new Array();<%dim jj=0do while not rs.eof%>//将小类表中的所有相关记录存到数组calArray的对应元素中。calArray[<%=j%>]=new Array("<%=rs("small_class_id")%>","<%=rs("small_class_name")%>","<%=rs("belongto_big_class")%>");<%j=j+1rs.movenextlooprs.closeset rs=nothing%>//给num赋值为记录总数num=<%=j%>function givevalue(myvalue){/*当选择大类列表的值不为空时首先清空小类下拉列表的所有项目。不然小类列表中的项目会叠加的。同时也是初始化 options 的值为0 */document.form3.small_class_select.length = 0;//循环写出请求的大类所对应的小类。 for (i=0;i < num; i++) { if (calArray[i][2] == myvalue) { document.form3.small_class_select.options[document.form3.small_class_select.length] = new Option(calArray[i][1], calArray[i][0],"",""); /*定义新的Option对象并赋值。options的索引值从0开始。new Option对象有4个属性,对应分别是:文本串、value、defaultSelect、selected。在这里只用了第一个和第二个。*/ } }}</script><script language="JavaScript">function chk1(){if (form1.big_class_name.value=="") { alert("请输入大类名称!"); form1.big_class_name.focus(); return false; }}function chk2(){if (form2.small_class_name.value=="") { alert("请输入小类名称!"); form2.small_class_name.focus(); return false; }}
</script></head>
<body background="background.jpg"><%dim rs,sql,noclassselect case request("action") case "addbigclass" addbigclass case "addsmallclass" addsmallclassend select%><div align="center"></div><table width="60%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr valign="middle"> <td height="48" colspan="3"> <div align="center"><font color="#999900"><b><font color="#FF0000">ASP</font>+<font color="#FF0000">JavaScript</font>+<font color="#FF0000">数据库</font> 级联下拉菜单</b></font></div></td> </tr> <tr> <td width="22%" height="21" valign="bottom"><a href="#" onClick="addbig()">添加大类</a> </td> <td width="22%" valign="bottom"><a href="#" onClick="addsmall()">添加小类</a></td> <td width="56%" valign="bottom"><a href="#" onClick="viewmenu()">预览效果</a></td> </tr> <tr> <td height="33" colspan="3" valign="top"> <hr align="left" width="60%" size="1" color="#999900"> </td> </tr> <tr> <td colspan="3" valign="top"> <div id="a" style="display:none"> <form name="form1" method="post" action="?action=addbigclass" onSubmit="return chk1()"> 大类名称: <input name="big_class_name" type="text" id="big_class_name" size="16"> <input type="submit" name="Submit" value=" 添 加 "> </form> </div> <div id="b" style="display:none"> <form name="form2" method="post" action="?action=addsmallclass" onSubmit="return chk2()"> 选择大类后添加小类: <select name="addselect"> <% set rs=server.CreateObject("adodb.recordset") sql="big_class" rs.open sql,conn,1,1 if rs.eof or rs.bof then %> <option selected>还没有添加大类</option> <% else do while not rs.eof %> <option value="<%=rs("big_class_id")%>"><%=trim(rs("big_class_name"))%></option> <% rs.movenext loop end if rs.close set rs=nothing %> </select> 小类名称: <input name="small_class_name" type="text" id="small_class_name" size="16"> <input type="submit" name="Submit2" value=" 添 加 "> </form> </div> <div id="c" style="display:block"> <form name="form3" method="post" action=""> <select name="big_class_select" onChange="givevalue(document.form3.big_class_select.options[document.form3.big_class_select.selectedIndex].value)"> <% dim firstid set rs=server.CreateObject("adodb.recordset") sql="select * from big_class order by big_class_id" rs.open sql,conn,1,1 if rs.eof or rs.bof then noclass=1 %> <option selected>还没有添加大类</option> <% else rs.movefirst firstid=rs("big_class_id") '在没有选择大类(页面刚载入)时要载入的大类。 %> <option value="<%=rs("big_class_id")%>" selected><%=trim(rs("big_class_name"))%></option> <% rs.movenext do while not rs.eof %> <option value="<%=rs("big_class_id")%>"><%=trim(rs("big_class_name"))%></option> <% rs.movenext loop end if rs.close set rs=nothing %> </select> <select name="small_class_select"> <%if noclass=1 then%> <option value="" selected>没有小类</option> <% else '在没有选择大类(页面刚载入)时要载入的小类,要跟默认的大类对应。 set rs=server.CreateObject("adodb.recordset") sql="select * from small_class where belongto_big_class="&firstid rs.open sql,conn,1,1 if rs.eof or rs.bof then %> <option value="" selected>没有小类</option> <% else do while not rs.eof %> <option value="<%=rs("small_class_id")%>"><%=trim(rs("small_class_name"))%></option> <% rs.movenext loop end if rs.close set rs=nothing end if %> </select> </form> </div></td> </tr></table><%sub addbigclass() set rs=server.CreateObject("adodb.recordset") sql="select * from big_class where big_class_name='"&trim(request("big_class_name"))&"'" rs.open sql,conn,1,3 if not(rs.eof and rs.bof) then response.Write("<script>alert('该大类已经存在!');</script>") else rs.addnew rs("big_class_name")=trim(request("big_class_name")) rs.update response.Write("<script>alert('大类添加成功!');self.location='test.asp?action=viewmenu';</script>") end if rs.close set rs=nothingend subsub addsmallclass() set rs=server.CreateObject("adodb.recordset") sql="select * from small_class where small_class_name='"&trim(request("small_class_name"))&"' and belongto_big_class="&request("addselect") rs.open sql,conn,1,3 if not(rs.eof and rs.bof) then response.Write("<script>alert('该小类已经存在!');</script>") else rs.addnew rs("belongto_big_class")=request("addselect") rs("small_class_name")=trim(request("small_class_name")) rs.update response.Write("<script>alert('小类添加成功!');self.location='test.asp?action=viewmenu';</script>") end if rs.close set rs=nothingend subconn.closeset conn=nothing%><table width="60%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="48%"> <div align="right">Copyright © </div></td> <td width="1%"> </td> <td width="11%"><b><a href="http://cooleasy.xicp.net/">酷易在线</a></b> </td> <td width="40%"><a href="mailto:xljxlj279@126.com">联系站长</a></td> </tr></table></body></html> |
|
回复:ASP+JavaScript+数据库 级联下拉菜单
|
ASP+JavaScript+数据库 级联下拉菜单 |
电脑与网络 adsad(游客)发表评论于2012/5/25 8:54:13 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
ASP+JavaScript+数据库 级联下拉菜单 |
电脑与网络 Justyle(游客)发表评论于2012/5/25 8:52:34 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
ASP+JavaScript+数据库 级联下拉菜单 |
电脑与网络 Jastyle(游客)发表评论于2012/5/25 8:51:50 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 学习(游客)发表评论于2011/1/7 21:57:49 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 学习(游客)发表评论于2011/1/7 21:57:49 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 学习(游客)发表评论于2011/1/7 21:57:48 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 学习(游客)发表评论于2011/1/7 21:57:46 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 xcxcxc(游客)发表评论于2009/6/12 16:14:20 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 superadmin(游客)发表评论于2009/2/23 10:06:15 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 wwwww(游客)发表评论于2008/5/20 11:36:43 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 trytry(游客)发表评论于2007/10/24 17:58:54 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 kevin(游客)发表评论于2006/11/27 23:57:10 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 sf(游客)发表评论于2006/10/29 20:37:08 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 KK(游客)发表评论于2006/5/9 15:48:50 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
有没有用jsp+JavaScript+数据库的级联下拉菜单的写法的 |
电脑与网络 mayixiaohei(游客)发表评论于2006/2/8 15:43:23 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
你能不能写一个简单的数据库下拉级联菜单的例子发到我的邮箱里面,我的邮箱是liuchao8319@yahoo.com.cn,我只希望怎样从数据库中读出来就行了!谢谢 |
电脑与网络 ghost1635(游客)发表评论于2005/11/19 15:33:33 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 23(游客)发表评论于2005/11/15 18:03:49 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 wolf(游客)发表评论于2005/11/9 21:33:02 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!--#include file="Connections/connMenu.asp" --><!--打开两个表,两个表用字段main_id=sub_id关联--><%dim sMainId,sSubId,sSubNameset rs1=server.CreateObject("adodb.recordset")sql1="select * from main"rs1.open sql1,MM_connMenu_STRING,1,3set rs2=server.CreateObject("adodb.recordset")sql2="select * from sub"rs2.open sql2,MM_connMenu_STRING,1,3'把字段处理成连成字符串if rs1.recordcount>0 thenrs1.movefirstsMainId=rs1.rs1("main_id")do while not rs1.eofif rs1.eof then exit dosMainId=sMainId & "," & rs1("main_id")loopend ifif rs2.recordcount>0 thenrs2.movefirstsSubId=rs2("sub_id")sSubName=rs2("sub_name")do while not rs2.eofif rs2.eof then exit dosSubId=sSubId & "," & rs2("main_id")sSubName=sSubName & "," & rs2("main_name")loopend if%><form name="form1"><%response.write "<input type=hidden name=txtMain value=" & sMainId & ">"response.write "<input type=hidden name=txtSubId value=" & sSubId & ">"response.write "<input type=hidden name=txtSubName value=" & sSubName & ">"%><!--建立菜单一--><select name="mainmenu" size="1" onChange="redirect(this.options.value)"><option value=0>请选择……</option><%while not rs1.eof%><option value="<%=rs1("main_id")%>"><%=rs1("main_name")%></option><%rs1.movenextwend%></select><!--建立菜单二--><select name="submenu" size="1"><option value=0>请选择</option></select></form><!--下面为具体实现的script语句--><script><!--function redirect(x){var i,nCount,strMainId,strSubId,strSubName,sTemp;strSubId=new Array();strSubName=new Array();sTemp=document.form1.txtSubId.value;strSubId=sTemp.split(",");sTemp=document.form1.txtSubName.value;strSubName=sTemp.split(",");nCount=0;for (i=0;i<strSubId.length;i++){if (x==strSubId[i]){nCount=nCount+1;}}document.form1.submenu.options.length=nCount;nCount=0;for (i=0;i<strSubId.length;i++){if (x==strSubId[i]){document.form1.submenu.options[nCount].value=strSubId[i];document.form1.submenu.options[nCount].text=strSubName[i];nCount=nCount+1;}}}//--></script>里面可能有点错误,我只是想表达这个意思,把数据一次性读出放在隐藏的控件中,必要时读取对应的就可以了。请多指教 |
电脑与网络 1414(游客|222.45.181.71)发表评论于2005/8/6 0:46:35 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 ASDD(游客|220.163.23.75)发表评论于2005/8/1 15:15:27 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 123(游客|60.211.143.18)发表评论于2005/7/30 20:03:06 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 8635(游客|58.24.216.103)发表评论于2005/7/30 15:38:23 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
2313123221321312323123212132132132111
2113112
12122121
1 |
电脑与网络 1212(游客|61.141.71.175)发表评论于2005/7/27 19:27:00 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 fdg(游客|218.71.80.248)发表评论于2005/7/19 11:52:13 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 ff(游客|222.211.24.86)发表评论于2005/7/18 11:45:58 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 dsfg(游客)发表评论于2005/7/7 15:57:12 |
| |
回复:ASP+JavaScript+数据库 级联下拉菜单
|
电脑与网络 111(游客)发表评论于2005/5/24 9:54:32 |
| |
» 1 »
|