基于asp+ajax和數(shù)據(jù)庫(kù)驅(qū)動(dòng)的二級(jí)聯(lián)動(dòng)菜單
更新時(shí)間:2010年05月06日 00:13:13 作者:
基于asp+ajax和數(shù)據(jù)庫(kù)驅(qū)動(dòng)的二級(jí)聯(lián)動(dòng)菜單,需要的朋友可以參考下。
index.asp 頁面代碼
<!--#include file="conn.asp" -->
<%
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%></option>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>
</select>
<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%></option>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = "<select name='smallclassid'><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(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>選擇二級(jí)分類</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果創(chuàng)建對(duì)象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加個(gè)隨機(jī)數(shù)。
xmlhttpobj.send(null);
}
}
function handle(){//客戶端監(jiān)控函數(shù)
//if(xmlhttpobj.readystate==4){//服務(wù)器處理請(qǐng)求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//獲得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="對(duì)不起,您請(qǐng)求的頁面有問題...";
}
//}
//else{
//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服務(wù)器處理中
//}
//}
}
getsubcategory.asp 代碼
<%@language="vbscript" codepage="936"%>
<!--#include file="conn.asp"-->
<%
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 "非法參數(shù)"
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 "查詢出錯(cuò)"
response.end
end if
if not p.eof then
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>"
else
html = "<select name='smallclassid'><option value='0' selected>暫無小類</option></select>"
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>
復(fù)制代碼 代碼如下:
<!--#include file="conn.asp" -->
<%
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%></option>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>
</select>
<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%></option>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = "<select name='smallclassid'><option value='0' selected>暫無小類</option></select>"
response.write html
end if
%>
</select>
</div>
ajax.js 代碼
復(fù)制代碼 代碼如下:
// 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="<select name='smallclassid'><option value='0' selected>選擇二級(jí)分類</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果創(chuàng)建對(duì)象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加個(gè)隨機(jī)數(shù)。
xmlhttpobj.send(null);
}
}
function handle(){//客戶端監(jiān)控函數(shù)
//if(xmlhttpobj.readystate==4){//服務(wù)器處理請(qǐng)求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//獲得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="對(duì)不起,您請(qǐng)求的頁面有問題...";
}
//}
//else{
//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服務(wù)器處理中
//}
//}
}
getsubcategory.asp 代碼
復(fù)制代碼 代碼如下:
<%@language="vbscript" codepage="936"%>
<!--#include file="conn.asp"-->
<%
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 "非法參數(shù)"
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 "查詢出錯(cuò)"
response.end
end if
if not p.eof then
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>"
else
html = "<select name='smallclassid'><option value='0' selected>暫無小類</option></select>"
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>
您可能感興趣的文章:
- PHP+ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)菜單功能示例
- ajax三級(jí)聯(lián)動(dòng)下拉菜單效果
- AJAX省市區(qū)三級(jí)聯(lián)動(dòng)下拉菜單(java版)
- ThinkPHP使用心得分享-ThinkPHP + Ajax 實(shí)現(xiàn)2級(jí)聯(lián)動(dòng)下拉菜單
- ajax讀取數(shù)據(jù)庫(kù)內(nèi)容實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉選擇菜單示例
- Ajax二級(jí)聯(lián)動(dòng)菜單實(shí)現(xiàn)原理及代碼
- 一個(gè)強(qiáng)健 實(shí)用的asp+ajax二級(jí)聯(lián)動(dòng)菜單(有演示和附源程序打包下載)
- 落伍首發(fā) php+mysql 采用ajax技術(shù)的 省 市 地 3級(jí)聯(lián)動(dòng)無刷新菜單 源碼
- 琥珀無限級(jí)分類聯(lián)動(dòng)菜單AJAX版
- Ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)菜單
相關(guān)文章
- 現(xiàn)在很多網(wǎng)站都存在跨站腳本攻擊漏洞,讓黑客有機(jī)可乘.跨站攻擊很容易就可以構(gòu)造,而且非常隱蔽,不易被查覺(通常盜取信息后馬上跳轉(zhuǎn)回原頁面)。如何攻擊,在此不作介紹,主要談?wù)勅绾畏婪丁?/div> 2015-09-09
PHP使用PDO操作數(shù)據(jù)庫(kù)的亂碼問題解決方法
這篇文章主要介紹了PHP使用PDO操作數(shù)據(jù)庫(kù)的亂碼問題解決方法,實(shí)例分析了編碼設(shè)置及屬性設(shè)置解決亂碼問題的實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-04-04php遞歸函數(shù)中使用return的注意事項(xiàng)
php遞歸函數(shù)中使用return的時(shí)候會(huì)碰到無法正確返回想要的值得情況,下面就來舉例子來說明一下吧2014-01-01php中strstr、strrchr、substr、stristr四個(gè)函數(shù)的區(qū)別總結(jié)
這篇文章主要介紹了php中strstr、strrchr、substr、stristr四個(gè)函數(shù)的區(qū)別總結(jié),這4個(gè)函數(shù)是PHP中常用的字符串相關(guān)函數(shù),需要的朋友可以參考下2014-09-09PHP的數(shù)組中提高元素查找與元素去重的效率的技巧解析
這篇文章主要介紹了PHP的數(shù)組中提高元素查找與元素去重的效率的技巧解析,文中對(duì)比了相關(guān)方法的執(zhí)行速度來總結(jié)數(shù)組中使元素查找和去重更加高效的辦法,需要的朋友可以參考下2016-03-03最新評(píng)論