开发学院WEB开发ASP 下拉框连动的小例子(数据库版) 阅读

下拉框连动的小例子(数据库版)

 2000-11-03 10:55:35 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹妞嬪孩顐芥慨姗嗗厳缂傛氨鎲稿鍫罕闂備礁婀遍搹搴ㄥ窗閺嶎偆涓嶆い鏍仦閻撱儵鏌i弴鐐测偓鍦偓姘炬嫹闂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗〒姘e亾妤犵偛顦甸弫鎾绘偐閹绘帞鈧參姊哄Ч鍥х仼闁诲繑鑹鹃悾鐑藉蓟閵夛妇鍘甸梺瑙勵問閸犳牠銆傛總鍛婄厱閹艰揪绱曟牎闂侀潧娲ょ€氫即鐛幒妤€绠f繝闈涘暙娴滈箖鏌i姀鈶跺湱澹曟繝姘厵闁绘劦鍓氶悘杈ㄤ繆閹绘帞澧涚紒缁樼洴瀹曞崬螖閸愬啠鍓濈换娑樼暆婵犱胶鏁栫紓浣介哺閹瑰洤鐣烽幒鎴僵闁瑰吀鐒﹂悗鎼佹⒒娴g儤鍤€闁搞倖鐗犻獮蹇涙晸閿燂拷濠电姷鏁告慨鐑藉极閸涘﹥鍙忔い鎾卞灩缁狀垶鏌涢幇闈涙灈鐎瑰憡绻冮妵鍕箻鐎靛摜鐣奸梺纭咁潐濞茬喎顫忕紒妯肩懝闁逞屽墮宀h儻顦查悡銈夋煏閸繃鍋繛宸簻鎯熼梺瀹犳〃閼冲爼宕濋敃鈧—鍐Χ閸℃鐟愰梺鐓庡暱閻栧ジ宕烘繝鍥у嵆闁靛骏绱曢崢顏堟⒑閹肩偛鍔楅柡鍛⊕缁傛帟顦寸紒杈ㄥ笚濞煎繘鍩℃担閿嬵潟闂備浇妗ㄩ悞锕傚箲閸ヮ剙鏋侀柟鍓х帛閺呮悂鏌ㄩ悤鍌涘闂傚倸鍊搁崐鎼佸磹妞嬪孩顐芥慨姗嗗厳缂傛氨鎲稿鍫罕闂備礁婀遍搹搴ㄥ窗閺嶎偆涓嶆い鏍仦閻撱儵鏌i弴鐐测偓鍦偓姘炬嫹  闂傚倸鍊搁崐鎼佸磹閻戣姤鍤勯柤鍝ユ暩娴犳氨绱撻崒娆掑厡缂侇噮鍨堕妴鍐川閺夋垹鍘洪悗骞垮劚椤︻垶宕¢幎鑺ョ厪闊洦娲栨牎闂佽瀵掗崜鐔奉潖閾忓湱纾兼俊顖氭惈椤矂姊洪崷顓涙嫛闁稿妫濋幆鈧い蹇撴祩濡嫰姊洪崫鍕拱婵炲弶岣块幑銏犫攽婵犲嫮鏉搁梺鍝勬川婵兘鎮伴妷鈺傗拻濞达絽鎼敮璺侯熆閻熷府鏀荤紒鍌氱Т楗即宕煎锝呬壕闁哄啫鐗嗙粈鍐┿亜韫囧海顦﹀ù婊堢畺閺屻劌鈹戦崱娑扁偓妤€顭胯閸犳牠婀侀梺缁樕戦悷銉р偓姘煎枤缁粯銈i崘鈺冨幈濡炪倖鍔戦崐鏇㈠几鎼淬劍鐓熼煫鍥ь儏閸旀粓鏌曢崶褍顏€殿喗娼欒灒闁告繂瀚濠碉紕鍋戦崐鎴﹀垂濞差亝鍋¢柍鍝勬噹缁犳牠鏌嶉埡浣告殲闁稿海鍠栭弻鏇㈠炊瑜嶇花濠氭煙閸戙倖瀚�
核心提示:asp文件:<%@ Language=VBScript %><%Option Explicit%><html><head><title>List</title><meta http-equiv="Content-Type"
asp文件:
<%@ Language=VBScript %>
<%Option Explicit%>
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn
dim rs
dim sql
dim count
dim rs1
dim sql1


set conn = server.CreateObject ("adodb.connection")
conn.Open "test","sa",""


sql = "select * from district order by locationid asc"
set rs = conn.execute(sql)
%>
<script language = "javaScript">
var onecount;
onecount=0;
subcat = new Array();
    <%
    count = 0
    do while not rs.eof
    %>
subcat[<%=count%>] = new Array("<%= trim(rs("districtname"))%>","<%= trim(rs("locationid"))%>","<%= trim(rs("districtid"))%>");
    <%
    count = count + 1
    rs.movenext
    loop
    rs.close
    set rs=nothing
    %>
onecount=<%=count%>;

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

  var locationid=locationid;
  var i;
  document.myform.smalllocation.options[0] = new Option('====所有地区====','');
  for (i=0;i < onecount; i++)
    {
      if (subcat[i][1] == locationid)
      {
        document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);
      }    
    }
    
  }  
</script>
</head>
<body>
<form name="myform" method="post">
  <select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)">
    <%
    
    sql1 = "select * from location order by locationname asc"
    set rs1 = conn.Execute (sql1)
    do while not rs1.eof
    %>
    <option value="<%=trim(rs1("locationid"))%>"><%=trim(rs1("locationname"))%></option>
    <%
    rs1.movenext
    loop
    rs1.close
    set rs1 = nothing
    conn.Close
    set conn = nothing
    %>
  </select>
  <select name="smalllocation">
    <option selected value="">==所有地区==</option>
  </select>
</form>
<script LANGUAGE="Javascript">
  changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value);
</script>
</body>
</html>


数据库:
create table location
(

locationid char(2) not null PRimary key,
locationname char(50) not null

)


create table district
(

districtid char(3) not null primary key,
districtname char(50) not null,
locationid char(2) not null
)

Tags:下拉 连动 例子

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接