ASP 製作連動菜單

來源:互聯網
上載者:User

  <%
response.write "<select name=""class_id"" onChange=""classselect(this);"">"&vbCrlf
strJS="function classselect(obj){for (var i=document.refer.class_c_id.options.length;i>=0;i--){document.refer.class_c_id.options[i]=null;"&vbCrlf '清除原有option對象的JS代碼
sql="select class_id,class_name from class order by class_order"
set rs=conn.execute(sql)
          while not rs.eof
          response.write "<option value="&rs("class_id")
                  if class_id<>"" then
                     if rs("class_id")=CInt(class_id) then '使相對應的父類的option上為selected。一定加CInt函數,否則不行
                        response.write " selected "
                     end if
                  end if
                  response.write ">"&rs("class_name")&"</option>"&vbCrlf
          strJS=strJS&"}"&vbCrlf&"if (obj.options[obj.selectedIndex].value=="&rs("class_id")&"){"&vbCrlf

          sql1="select class_c_id,class_c_name from class_c where class_id="&rs("class_id")&" order by class_c_order"
          set rs1=conn.execute(sql1)
                  
                  while not rs1.eof
                  strJS=strJS&"document.refer.class_c_id.options[document.refer.class_c_id.options.length]=new Option('"&rs1("class_c_name")&"','"&rs1("class_c_id")&"');"&vbCrlf
                  rs1.movenext
                  wend

          rs.movenext
          wend
                  
                  '為了使第一個子類的option不為空白====================================================
                  if class_id="" then
                     sql="select class_id,class_name from class"
                         set rs=conn.execute(sql)
                     sql="select class_c_id,class_c_name from class_c where class_id="&rs("class_id")&" order by class_c_order"
                  else
                     sql="select class_c_id,class_c_name from class_c where class_id="&class_id&" order by class_c_order"
                  end if
              set rs=conn.execute(sql)
                  while not rs.eof
                  if class_c_id<>"" then         
                       if rs("class_c_id")=CInt(class_c_id) then '使相對應的子類的option上為selected。if放在字串串連前面
                               strJS3="var option_length=document.refer.class_c_id.options.length;"&vbCrlf
                           strJS2="document.refer.class_c_id.options[option_length].selected=true;"&vbCrlf
                           else
                               strJS3=""          
                           end if
                  end if          
                  strJS1=strJS1&strJS3&"document.refer.class_c_id.options[document.refer.class_c_id.options.length]=new Option('"&rs("class_c_name")&"','"&rs("class_c_id")&"');"&vbCrlf
                  rs.movenext
                  wend
                  '==================================================================================
                  
          strJS=strJS&"}"&vbCrlf&"}"& vbCrlf
                  response.write " </select>"
          response.write "<select name=""class_c_id"">"
          response.write "</select>"
          response.write "<script language=""JavaScript"">"&vbCrlf '輸出JS指令碼
                  response.write strJS1&vbCrlf&strJS2&vbCrlf
          response.write strJS&"</SCRIPT>"&vbCrlf
conn.close
set conn=nothing
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.