经理
业务
您现在的位置:首页 >> 网站设计 >> 内容

基于asp网站制作+ajax和数据库驱动的二级联动菜单

基于asp网站制作+ajax和数据库驱动的二级联动菜单,需要的朋友可以参考下。

index.html网站制作 页面代码


<!--#include file="conn.asp网站制作" -->
<%
set cmd = conn.execute("select bigaaaaa/classid,bigaaaaa/classname from bigaaaaa/class")
tempid=cmd("bigaaaaa/classid")
%>
<select name="menu" onChange="getsubcategory(this.value);">

<%
if not cmd.eof then
do while not cmd.eof
bigaaaaa/classid= cmd("bigaaaaa/classid")
bigaaaaa/classname = cmd("bigaaaaa/classname")
%>
<option value="<%=bigaaaaa/classid%>"><%=bigaaaaa/classname%></option>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>
</select>
<div id="subaaaaa/class">
<select name="submenu">

<%
set cxd = conn.execute("select * from smallaaaaa/class where bigaaaaa/classid=" & tempid)
if not cxd.eof then
do while not cxd.eof
smallaaaaa/classid= cxd("smallaaaaa/classid")
smallaaaaa/classname = cxd("smallaaaaa/classname")%>
<option value="<%=smallaaaaa/classid%>"><%=smallaaaaa/classname%></option>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = "<select name='smallaaaaa/classid'><option value='0' selected>暂无小类</option></select>"
response.write html
end if
%>
</select>
</div>


ajax.js 代码


// javascript Document
function createxmlhttp()
{
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}

function getsubcategory(bigaaaaa/classid){
if(bigaaaaa/classid==0){
document.getElementById("subaaaaa/class").innerHTML="<select name='smallaaaaa/classid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp网站制作?bigaaaaa/classid="+bigaaaaa/classid+"&number="+Math.random(),true);//get方法 加个随机数。


xmlhttpobj.send(null);
}
}

function handle(){//客户端监控函数
//if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subaaaaa/class").innerHTML=html;
}else{
document.getElementById("subaaaaa/class").innerHTML="对不起,您请求的页面有问题...";
}
//}
//else{
//document.getElementById("subaaaaa/class").innerHTML=xmlhttpobj.readystate;//服务器处理中
//}
//}

}


getsubcategory.asp网站制作 代码


<%@language="vbscript" codepage="936"%>
<!--#include file="conn.asp网站制作"-->
<%
response.charset="gb2312"
bigaaaaa/classid=safe(request.querystring("bigaaaaa/classid"))
if bigaaaaa/classid<>"" then
set re=new regexp
re.ignorecase=true
re.global=false
re.pattern = "^[0-9]{1,3}$"
if not re.test(bigaaaaa/classid) then
response.write "非法参数"
response.end
end if%>

<%on error resume next
set p = conn.execute("select * from smallaaaaa/class where bigaaaaa/classid=" & bigaaaaa/classid)
if err then
err.clear
response.write "查询出错"
response.end
end if
if not p.eof then
html = "<select name='select2'>"&vbnewline
do while not p.eof
html = html&"<option value='"&p("smallaaaaa/classid")&"'>"&p("smallaaaaa/classname")&"</option>"&vbnewline
p.movenext
loop
html = html&"</select>"
else
html = "<select name='smallaaaaa/classid'><option value='0' selected>暂无小类</option></select>"
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>

  • 九维软件科技有限公司 © 2010 版权所有 All Rights Resverved 未经授权,禁止复制、转播本站信息,经授权的引用必须注明出自本站 。
    Email:deuv@163.com 电话:0513-85338199 苏ICP备10045045号