佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 一個強健 實用的asp+ajax二級聯(lián)動菜單(有演示和附源程序打包下載)

一個強健 實用的asp+ajax二級聯(lián)動菜單(有演示和附源程序打包下載)

熱門標簽:團購網(wǎng)站 銀行業(yè)務 服務器配置 科大訊飛語音識別系統(tǒng) Linux服務器 Mysql連接數(shù)設置 電子圍欄 阿里云
一個強健 實用的ajax二級聯(lián)動菜單(有演示和附源程序打包下載)

前些天在搞后臺的時候要用到二級聯(lián)動的菜單,到網(wǎng)上去找了半天也沒找到滿意的,不是這錯就是那錯,在選擇的時候有時候不能返回.真是郁悶.
     后來就看到有人用ajax寫了無限級分類(牛,呵呵,本人看不懂.).就想到我那個后臺不也可以用ajax試試,雖然比用javascript的慢點,但我這個實用.強健..不會出錯,也不會選擇某個大類后再返回無選擇狀態(tài)小類為空的狀態(tài).呵呵.
文件目錄:如圖

主要代碼如下:
index.asp
復制代碼 代碼如下:

%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="Content-Type" c />
title>Ajax的二級聯(lián)動by啊峰/title>
script language="javascript" src="js.js">/script>
/head>
body>
h2>a >Ajax的二級聯(lián)動by啊峰/a>/h2>
!--#include file="iconn.asp"-->

Set afeng = Conn.Execute("select bigclassid,bigclassname from bigclass")
%>
form id="form1" name="form1" method="post" action="">
  div id="bigclass" style="float:left">
  select name="select" >
     option value="0">選擇一級分類/option>
      %If Not afeng.Eof then
        Do While Not afeng.Eof
            bigclassid= afeng("bigclassid")
            bigclassname = afeng("bigclassname")%>
            option value="%=bigclassid%>">%=bigclassname%>/option>
        %afeng.Movenext
        Loop
    End If
    afeng.Close
    Set afeng = Nothing
    Conn.Close
    Set Conn = Nothing%>
  /select>
  /div>
  div id="subclass"  style="float:left">select name="select2">
    option value="0">選擇二級分類/option>
  /select>
  /div>
/form>
/body>
/html>

getsubcategory.asp文件:
復制代碼 代碼如下:

%
Response.Charset="GB2312" '設置字符集 原默認為utf-8
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%>
!--#include file="iconn.asp"-->
    %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 = "select name='smallclassid'>"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
%>

iconn.asp文件: 
復制代碼 代碼如下:

%
Set conn=server.CreateObject("adodb.connection")
db = "$#yeahdown.com@$$$@@%%.asp"
C  Server.MapPath(db)
On Error Resume Next
conn.open ConnStr
If Err Then
    Err.Clear
    Response.Write "div id=""error"">連接數(shù)據(jù)庫出錯/div>"
    Response.End
End If

Function safe(Str)
If Isnull(Str) Then
     safe = ""
     Exit Function 
End If
Str = Replace(Str,Chr(0),"", 1, -1, 1)
Str = Replace(Str, """", """, 1, -1, 1)
Str = Replace(Str,"","", 1, -1, 1)
Str = Replace(Str,">",">", 1, -1, 1) 
Str = Replace(Str, "script", "script", 1, -1, 0)
Str = Replace(Str, "SCRIPT", "SCRIPT", 1, -1, 0)
Str = Replace(Str, "Script", "Script", 1, -1, 0)
Str = Replace(Str, "script", "Script", 1, -1, 1)
Str = Replace(Str, "object", "object", 1, -1, 0)
Str = Replace(Str, "OBJECT", "OBJECT", 1, -1, 0)
Str = Replace(Str, "Object", "Object", 1, -1, 0)
Str = Replace(Str, "object", "Object", 1, -1, 1)
Str = Replace(Str, "applet", "applet", 1, -1, 0)
Str = Replace(Str, "APPLET", "APPLET", 1, -1, 0)
Str = Replace(Str, "Applet", "Applet", 1, -1, 0)
Str = Replace(Str, "applet", "Applet", 1, -1, 1)
Str = Replace(Str, "[", "[")
Str = Replace(Str, "]", "]")
Str = Replace(Str, """", "", 1, -1, 1)
Str = Replace(Str, "=", "=", 1, -1, 1)
Str = Replace(Str, "'", "''", 1, -1, 1)
Str = Replace(Str, "select", "select", 1, -1, 1)
Str = Replace(Str, "execute", "execute", 1, -1, 1)
Str = Replace(Str, "exec", "exec", 1, -1, 1)
Str = Replace(Str, "join", "join", 1, -1, 1)
Str = Replace(Str, "union", "union", 1, -1, 1)
Str = Replace(Str, "where", "where", 1, -1, 1)
Str = Replace(Str, "insert", "insert", 1, -1, 1)
Str = Replace(Str, "delete", "delete", 1, -1, 1)
Str = Replace(Str, "update", "update", 1, -1, 1)
Str = Replace(Str, "like", "like", 1, -1, 1)
Str = Replace(Str, "drop", "drop", 1, -1, 1)
Str = Replace(Str, "create", "create", 1, -1, 1)
Str = Replace(Str, "rename", "rename", 1, -1, 1)
Str = Replace(Str, "count", "count", 1, -1, 1)
Str = Replace(Str, "chr", "chr", 1, -1, 1)
Str = Replace(Str, "mid", "mid", 1, -1, 1)
Str = Replace(Str, "truncate", "truncate", 1, -1, 1)
Str = Replace(Str, "nchar", "nchar", 1, -1, 1)
Str = Replace(Str, "char", "char", 1, -1, 1)
Str = Replace(Str, "alter", "alter", 1, -1, 1)
Str = Replace(Str, "cast", "cast", 1, -1, 1)
Str = Replace(Str, "exists", "exists", 1, -1, 1)
Str = Replace(Str,Chr(13),"br>", 1, -1, 1)
safe = Replace(Str,"'","''", 1, -1, 1)
End Function
%>

最后一個js.js 
復制代碼 代碼如下:

function createxmlhttp()
{
    xmlhttpobj = false;
    try{//創(chuàng)建對象,一個一個的試,哎,要是能統(tǒng)一標準都好。。
        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>選擇二級分類/option>/select>";
        return;
    };
    var xmlhttpobj = createxmlhttp();
    if(xmlhttpobj){//如果創(chuàng)建對象xmlhttpobj成功
        xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"number="+Math.random(),true);//get方法 加個隨機數(shù)。
        xmlhttpobj.send(null);
        xmlhttpobj.onreadystatechange=function(){//客戶端監(jiān)控函數(shù)
            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="加載中,請梢候...";//服務器處理中
            }
        }    
    }
}

打包文件下載
您可能感興趣的文章:
  • PHP+ajax實現(xiàn)二級聯(lián)動菜單功能示例
  • ajax三級聯(lián)動下拉菜單效果
  • AJAX省市區(qū)三級聯(lián)動下拉菜單(java版)
  • ThinkPHP使用心得分享-ThinkPHP + Ajax 實現(xiàn)2級聯(lián)動下拉菜單
  • ajax讀取數(shù)據(jù)庫內(nèi)容實現(xiàn)二級聯(lián)動下拉選擇菜單示例
  • Ajax二級聯(lián)動菜單實現(xiàn)原理及代碼
  • 基于asp+ajax和數(shù)據(jù)庫驅(qū)動的二級聯(lián)動菜單
  • 落伍首發(fā) php+mysql 采用ajax技術的 省 市 地 3級聯(lián)動無刷新菜單 源碼
  • 琥珀無限級分類聯(lián)動菜單AJAX版
  • Ajax實現(xiàn)二級聯(lián)動菜單

標簽:蚌埠 廣元 江蘇 衡水 衢州 棗莊 萍鄉(xiāng) 大理

巨人網(wǎng)絡通訊聲明:本文標題《一個強健 實用的asp+ajax二級聯(lián)動菜單(有演示和附源程序打包下載)》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    浦北县| 抚州市| 克什克腾旗| 高平市| 甘洛县| 宾阳县| 同德县| 临沧市| 邓州市| 漳浦县| 安国市| 南川市| 柏乡县| 罗田县| 左权县| 荆门市| 孟连| 图们市| 共和县| 读书| 闵行区| 临武县| 镇原县| 新平| 襄垣县| 繁峙县| 赤峰市| 进贤县| 无为县| 铁岭市| 汽车| 汝州市| 宁武县| 封开县| 神池县| 榕江县| 山阴县| 金堂县| 甘孜| 商河县| 治县。|