时间:2021-07-01 10:21:17 帮助过:8人阅读
- <br><!--#include file="conn.asp" --> <br><% <br>set cmd = conn.execute("select bigclassid,bigclassname from bigclass") <br>tempid=cmd("bigclassid") <br>%> <br><select name="menu" onchange="getsubcategory(this.value);"> <% if not cmd.eof then do while not cmd.eof bigclassid= cmd("bigclassid") bigclassname = cmd("bigclassname") %> <option value="<%=bigclassid%>"><%=bigclassname%></option> <% cmd.movenext loop end if cmd.close set cmd = nothing %> </select> <br> <br><select name="submenu"> <% set cxd = conn.execute("select * from smallclass where bigclassid=" & tempid) if not cxd.eof then do while not cxd.eof smallclassid= cxd("smallclassid") smallclassname = cxd("smallclassname")%> <option value="<%=smallclassid%>"><%=smallclassname%></option> <% cxd.movenext loop cxd.close set cxd = nothing else html = "</select><option value="0" selected="">暂无小类</option>" <br>response.write html <br>end if <br>%> <br> <br> <br> <br>ajax.js 代码 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>// JavaScript Document <br>function createxmlhttp() <br>{ <br>xmlhttpobj = false; <br>try{ <br>xmlhttpobj = new XMLHttpRequest; <br>}catch(e){ <br>try{ <br>xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP"); <br>}catch(e2){ <br>try{ <br>xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP"); <br>}catch(e3){ <br>xmlhttpobj = false; <br>} <br>} <br>} <br>return xmlhttpobj; <br>} <br><br>function getsubcategory(bigclassid){ <br>if(bigclassid==0){ <br>document.getElementById("subclass").innerHTML="<select name="smallclassid"><option value="0" selected="">选择二级分类</option></select>"; <br>return; <br>}; <br>var xmlhttpobj = createxmlhttp(); <br>if(xmlhttpobj){//如果创建对象xmlhttpobj成功 <br>xmlhttpobj.onreadystatechange=handle; <br>xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。 <br><br><br>xmlhttpobj.send(null); <br>} <br>} <br><br>function handle(){//客户端监控函数 <br>//if(xmlhttpobj.readystate==4){//服务器处理请求完成 <br>if(xmlhttpobj.status==200){ <br>//alert('ok'); <br>var html = xmlhttpobj.responseText;//获得返回值 <br>document.getElementById("subclass").innerHTML=html; <br>}else{ <br>document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题..."; <br>} <br>//} <br>//else{ <br>//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服务器处理中 <br>//} <br>//} <br><br>} <br> <br>getsubcategory.asp 代码 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><%@language="vbscript" codepage="936"%> <br><!--#include file="conn.asp"--> <br><% <br>response.charset="gb2312" <br>bigclassid=safe(request.querystring("bigclassid")) <br>if bigclassid<>"" then <br>set re=new regexp <br>re.ignorecase=true <br>re.global=false <br>re.pattern = "^[0-9]{1,3}$" <br>if not re.test(bigclassid) then <br>response.write "非法参数" <br>response.end <br>end if%> <br><br><%on error resume next <br>set p = conn.execute("select * from smallclass where bigclassid=" & bigclassid) <br>if err then <br>err.clear <br>response.write "查询出错" <br>response.end <br>end if <br>if not p.eof then <br>html = "<select name="select2">"&vbnewline do while not p.eof html = html&"<option value=""&p("smallclassid")&"">"&p("smallclassname")&"</option>"&vbnewline p.movenext loop html = html&"</select>" <br>else <br>html = "<select name="smallclassid"><option value="0" selected="">暂无小类</option></select>" <br>end if <br>p.close <br>set p = nothing <br>conn.close <br>set conn = nothing <br>response.write html <br>html = "" <br>end if <br>%> <br> </li></ol></pre></li></ol></pre>