加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 23:34:56 所属栏目:百科 来源:网络整理
导读:index.asp 页面代码 div class="codetitle" a style="CURSOR: pointer" data="92950" class="copybut" id="copybut92950" onclick="doCopy('code92950')" 代码如下: div class="codebody" id="code92950" % set cmd = conn.execute("select bigclassid,bigcl

index.asp 页面代码
<div class="codetitle"><a style="CURSOR: pointer" data="92950" class="copybut" id="copybut92950" onclick="doCopy('code92950')"> 代码如下:<div class="codebody" id="code92950">

<%
set cmd = conn.execute("select bigclassid,bigclassname from bigclass")
tempid=cmd("bigclassid")
%>
<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%>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>

<div id="subclass">
<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%>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = ""
response.write html
end if
%>



ajax.js 代码
<div class="codetitle"><a style="CURSOR: pointer" data="84664" class="copybut" id="copybut84664" onclick="doCopy('code84664')"> 代码如下:<div class="codebody" id="code84664">
// 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(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&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("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题...";
}
//}
//else{
//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服务器处理中
//}
//} }

getsubcategory.asp 代码
<div class="codetitle"><a style="CURSOR: pointer" data="62637" class="copybut" id="copybut62637" onclick="doCopy('code62637')"> 代码如下:<div class="codebody" id="code62637">
<%@language="vbscript" codepage="936"%>

<%
response.charset="gb2312"
bigclassid=safe(request.querystring("bigclassid"))
if bigclassid<>"" then
set re=new regexp
re.ignorecase=true
re.global=false
re.pattern = "^[0-9]{1,3}$"
if not re.test(bigclassid) then
response.write "非法参数"
response.end
end if%> <%on error resume next
set p = conn.execute("select
from smallclass where bigclassid=" & bigclassid)
if err then
err.clear
response.write "查询出错"
response.end
end if
if not p.eof then
html = ""
else
html = ""
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读