<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      對于SELECT的無限級聯(省|市|縣|鄉|村|...)

      [摘要]index.asp程序代碼: <html><head><title></title><meta content="text/html; charset=gb2312" http-equiv="content-typ...

      index.asp
      程序代碼:
      <html>
      <head>
      <title></title>
      <meta content="text/html; charset=gb2312" http-equiv="content-type">
      <style type="text/css"><!--
        FONT{font-size:12px}
        TD{font-size:12px}
        A{color:#333399}
        A:hover{color:#FF6600}
      --></style>
      <script language="JavaScript" type="text/JavaScript"><!--
      function funOnload(){
        document.all.list_file.src="jscript_city.asp?base=0&sele=0-&elem=Select01";
      }

      //pBase級數,以0基,
      //pSele是<option 的value值
      //pEle是下一級的表單名字
      function chgSelect(pBase,pSele,pElem){
        //當改變了一個列表之后。清除以后的列表的值。
        for(i=parseInt(pElem.replace("Select",""));i<=5;i++){
          var tmp="000"+i;
          var pElem1=eval("document.Form1.Select"+tmp.substr(tmp.length-2));

          pElem1.length=1;
          pElem1.selectedIndex=0;
        }

        //JS用ASP得到數據庫的數據來更新下級列表
        document.all.list_file.src="jscript_city.asp?base="+pBase+"&sele="+pSele+"&elem="+pElem;
      }

      //--></script>
      <script id="list_file" language="JavaScript" type="text/JavaScript" src=""></script>
      </head>

      <body bgcolor="#FFFFFF" leftmargin="0" topmargin="2" text="#333333" onload="funOnload();">
      <form name="Form1">
      <select name="Select01" onchange="chgSelect(1,this.options[this.selectedIndex].value,'Select02')">
        <option value="">省...</option>
      </select>
      <select name="Select02" onchange="chgSelect(2,this.options[this.selectedIndex].value,'Select03')">
        <option value="">市...</option>
      </select>
      <select name="Select03" onchange="chgSelect(3,this.options[this.selectedIndex].value,'Select04')">
        <option value="">縣...</option>
      </select>
      <select name="Select04" onchange="chgSelect(4,this.options[this.selectedIndex].value,'Select05')">
        <option value="">鄉...</option>
      </select>
      <select name="Select05">
        <option value="">村...</option>
      </select>
      </form>
      </body></html> 


      'jscript_city.asp
      程序代碼:
      <%
      ' varBase 下拉菜單等級
      ' varSele 所選擇下拉菜單項的數據庫ID
      ' varElem 下一級的表單名稱

      varBase=Request.QueryString("base")
      varSele=Left(Request.QueryString("sele"),InStr(Request.QueryString("sele"),"-")-1)
      varElem=Request.QueryString("elem")

      varDistName=""
      varAutoID=""

      Set conDB=Server.CreateObject("ADODB.CONNECTION")
      conDB.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("db1.mdb")

      sqlCommand="select * from table1 where filed1="&varBase&" and filed2="&varSele
      Set rsRecord=conDB.Execute(sqlCommand)

      While Not rsRecord.eof
        varDistName=varDistName&chr(34)&rsRecord("filed3")&chr(34)
        varAutoID=varAutoID&chr(34)&rsRecord("id")&chr(34)

        rsRecord.movenext
        If Not rsRecord.Eof Then
          varDistName=varDistName&","
          varAutoID=varAutoID&","
        End If
      Wend

      Response.Write("var varDistName=new Array("&varDistName&")"&vbcrlf)
      Response.Write("var varAutoID=new Array("&varAutoID&")"&vbcrlf)

      Response.Write("var varElem=eval("&chr(34)&"document.Form1."&varElem&chr(34)&")"&vbcrlf)

      Response.Write("varElem.length=varDistName.length+1;"&vbcrlf)

      Response.Write("for(var i=0;i<varDistName.length;i++){"&vbcrlf)
      Response.Write("    varElem.options[i+1].text=varDistName;"&vbcrlf)
      Response.Write("    varElem.options[i+1].value=varAutoID+'-'+varDistName;"&vbcrlf)
      Response.Write("}"&vbcrlf)

      Response.Write("varElem.selectedIndex=0;"&vbcrlf)

      %> 

      db1.mdb
      '-------------------------------------------------
      福建 廈門 思明 黃厝 曾厝桉村
      福建 泉州 豐澤 西湖 水頭村

      如上面的五級轉成數據庫為:
      '-------------------------------
      id    filed1    filed2    filed3
      1    0        0        福建
      2    1        1        廈門
      3    1        1        泉州
      4    2        2        思明
      5    3        4        黃厝
      6    4        5        曾厝桉村
      7    2        3        豐澤
      8    3        7        西湖
      9    4        8        水頭村
      '-------------------------------------------------
      數據庫說明:
      id 自動編號
      filed1 下拉菜單列表的等級(看級數。可以設置它的精度。是數字類型)
      filed2 上一級的id號(用長整型吧)
      filed3 這個就不用說了吧(文件。長度自己看情況)

      本程序在IIS4+WIN2000P+ACCESS2000下通過。




      日韩精品一区二区三区高清