<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
        當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

        ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼

        來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:52:38
        文檔

        ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼

        ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼: 代碼如下:<% '數(shù)據(jù)庫(kù)字段為類(lèi)屬性,添加、刪除、修改、操作檢查等函數(shù)為類(lèi)的方法 Class Cls_Leibie Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定義私有變量(
        推薦度:
        導(dǎo)讀ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼: 代碼如下:<% '數(shù)據(jù)庫(kù)字段為類(lèi)屬性,添加、刪除、修改、操作檢查等函數(shù)為類(lèi)的方法 Class Cls_Leibie Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定義私有變量(

        代碼如下:
        <%
        '數(shù)據(jù)庫(kù)字段為類(lèi)屬性,添加、刪除、修改、操作檢查等函數(shù)為類(lèi)的方法
        Class Cls_Leibie
            Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定義私有變量(類(lèi)的屬性,即數(shù)據(jù)庫(kù)字段對(duì)應(yīng)的變量)
            Private rs,sql,ErrorStr

            Private Sub Class_Initialize()
                ErrorStr=""                    '初始化錯(cuò)誤信息為空
            End Sub

            Private Sub Class_Terminate()    '銷(xiāo)毀類(lèi)時(shí)關(guān)閉數(shù)據(jù)庫(kù)連接
                If IsObject(Conn) Then 
                    Conn.Close
                    Set Conn = Nothing
                End If
            End Sub

        '*******************設(shè)置各個(gè)屬性******************************************************    
            Public Property Let ClassID(str)    '獲取類(lèi)別ID(主鍵)
                nClassID=str
                call ClassProperty()            '獲取類(lèi)別ID時(shí)調(diào)用此函數(shù)讀出類(lèi)的所有屬性
            End Property
            Public Property Let ClassName(str)    '獲取類(lèi)別名稱
                sClassName=str
            End Property

            Public Property Get ClassName
                ClassName=sClassName
            End Property

            Public Property Let ParentID(str)    '獲取類(lèi)別父ID
                nParentID=str
            End Property

            Public Property Get ParentID
                ParentID=nParentID
            End Property

            Public Property Let ParentPath(str)    '獲取父路徑ID
                sParentPath=str
            End Property

            Public Property Get ParentPath
                ParentPath=sParentPath
            End Property

            Public Property Let Depth(str)        '獲取類(lèi)別深度
                nDepth=str
            End Property

            Public Property Get Depth
                Depth=nDepth
            End Property

            Public Property Let RootID(str)        '獲取類(lèi)別根ID
                nRootID=str
            End Property

            Public Property Get RootID
                RootID=nRootID
            End Property

            Public Property Let Child(str)        '子類(lèi)別個(gè)數(shù)
                nChild=str
            End Property

            Public Property Get Child
                Child=nChild
            End Property

            Public Property Let OrderID(str)    '排序ID
                nOrderID=str
            End Property

            Public Property Get OrderID
                OrderID=nOrderID
            End Property
            Public Property Let FilePath(str)    '類(lèi)別文件根目錄(生成靜態(tài)文件路徑,小站奇人異事網(wǎng)([url]www.guaishi.org[/url])用的是生成靜態(tài),故設(shè)置此字段)
                sFilePath=str
            End Property

            Public Property Get FilePath
                FilePath=sFilePath
            End Property    
        '******************************************************************************

            Private Sub ClassProperty()            '讀取類(lèi)的所有屬性
                sql="select * from ArticleClass where ClassID="& nClassID
                set rs=conn.execute(sql)
                if not rs.eof then
                    sClassName=trim(rs("ClassName"))
                    nParentID=trim(rs("ParentID"))
                    sParentPath=trim(rs("ParentPath"))
                    nDepth=trim(rs("Depth"))
                    nRootID=trim(rs("RootID"))
                    nChild=trim(rs("Child"))
                    nOrderID=trim(rs("OrderID"))
                    sFilePath=trim(rs("FilePath"))
                end if
                set rs=nothing        
            End Sub

            Public Function FAddCheck()        '類(lèi)別添加檢查函數(shù),結(jié)果為0表示通過(guò)檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫(xiě)入錯(cuò)誤變量ErrorStr
                dim temprs
                FAddCheck=0
                if sClassName="" then        '類(lèi)名為空
                    FAddCheck=1
                    ErrorStr="類(lèi)名不能為空!"
                    exit Function
                else            
                    if nParentID="" then        '父id為空
                        FAddCheck=1
                        ErrorStr="父id不能為空!"
                        exit Function
                    else
                        if nParentID<>0 then
                            set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID)        '父類(lèi)別不存在
                            if temprs.eof then
                                FAddCheck=1
                                ErrorStr="所屬類(lèi)別不存在或已經(jīng)被刪除!"
                                exit Function
                            else
                                sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID        '類(lèi)名重復(fù)
                                set rs=conn.execute(sql)
                                if not rs.eof then
                                    FAddCheck=1
                                    ErrorStr="類(lèi)名重復(fù)!"
                                    exit Function
                                end if
                                set rs=nothing
                            end if
                            set temprs=nothing
                        else
                            sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID        '類(lèi)名重復(fù)
                            set rs=conn.execute(sql)
                            if not rs.eof then
                                FAddCheck=1
                                ErrorStr="類(lèi)名重復(fù)!"
                                exit Function
                            end if
                            set rs=nothing    
                        end if
                    end if
                end if
            End Function

            Public Sub SAdd()
                dim maxClassID,maxRootID
                set rs = conn.execute("select Max(ClassID) from ArticleClass")        '查找當(dāng)前數(shù)據(jù)庫(kù)中最大的類(lèi)別id,如果沒(méi)有數(shù)據(jù)則設(shè)置為0,要插入的類(lèi)別id為當(dāng)前最大id加1
                maxClassID=rs(0)
                if isnull(maxClassID) then
                    maxClassID=0
                end if
                set rs=nothing
                nClassID=maxClassID+1
                set rs=conn.execute("select max(rootid) From ArticleClass")        '查找當(dāng)前數(shù)據(jù)庫(kù)中最大的根id,如果沒(méi)有數(shù)據(jù)則設(shè)置為0,要插入的根id為當(dāng)前最大根id加1
                maxRootID=rs(0)
                if isnull(maxRootID) then
                    maxRootID=0
                end if
                nRootID=maxRootID+1
                set rs=conn.execute("select RootID,Depth,ParentPath,Child,OrderID From ArticleClass where ClassID=" & nParentID)    '查找父類(lèi)別相應(yīng)信息
                if not rs.eof then
                    nRootID=trim(rs("Rootid"))        '根id與父類(lèi)別根id相同
                    sParentPath=trim(rs("ParentPath"))& "," &nParentID    
                    if cint(trim(nParentID))>0 then            '父id大于0則有父類(lèi)別,故要插入的類(lèi)別的深度父類(lèi)別的深度加1,父id不大于0則當(dāng)前要插入的類(lèi)別為根類(lèi)別,則深度為0
                        nDepth=cint(trim(rs("Depth")))+1
                    else
                        nDepth=0
                    end if
                    if cint(trim(rs("Child")))>0 then
                        dim rsPrevOrderID
                        '得到與本欄目同級(jí)的最后一個(gè)欄目的OrderID
                        set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentID=" & ParentID)
                        prevOrderID=rsPrevOrderID(0)
                        '得到同一父欄目但比本欄目級(jí)數(shù)大的子欄目的最大OrderID,如果比前一個(gè)值大,則改用這個(gè)值。
                        set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentPath like '" & ParentPath & ",%'")
                        if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
                            if not IsNull(rsPrevOrderID(0))  then
                                 if rsPrevOrderID(0)>prevOrderID then
                                    prevOrderID=rsPrevOrderID(0)
                                end if
                            end if
                        end if
                        set rsPrevOrderID=nothing
                    end if
                    nOrderID=prevOrderID+1
                else
                    nOrderID=0
                    sParentPath="0"
                    nDepth=0
                end if
                set rs=nothing
                nChild=0
                sql="insert into ArticleClass (ClassID,ClassName,ParentID,ParentPath,Depth,RootID,Child,OrderID,FilePath) values ("& nClassID &",'"& sClassName &"',"& nParentID &",'"& sParentPath &"',"& nDepth &","& nRootID &","& nChild &","& nOrderID &",'"& sFilePath &"')"
                conn.execute(sql)
                if ParentID>0 then
                '更新其父類(lèi)的子欄目數(shù)
                    conn.execute("update ArticleClass set child=child+1 where ClassID="& nParentID)

                '更新該欄目排序以及大于本需要和同在本分類(lèi)下的欄目排序序號(hào)
                    if prevOrderID<>"" then
                        conn.execute("update ArticleClass set OrderID=OrderID+1 where rootid=" & nRootid & " and OrderID>"& prevOrderID &" and ClassID<>"& nClassID)
                    end if
                end if
            End Sub
            Public Function FEditCheck()    '類(lèi)別修改檢查函數(shù),結(jié)果為0表示通過(guò)檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫(xiě)入錯(cuò)誤變量ErrorStr
                dim temprs
                FEditCheck=0
                if nClassID="" then                    '類(lèi)別id為空
                    FEditCheck=1
                    ErrorStr="類(lèi)別id不能為空!"
                    exit Function
                else                
                    if sClassName="" then            '類(lèi)名為空
                        FEditCheck=1
                        ErrorStr="類(lèi)名不能為空!"
                        exit Function
                    else
                        if nParentID<>0 then
                            set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID)        '父類(lèi)別不存在
                            if temprs.eof then
                                FAddCheck=1
                                ErrorStr="所屬類(lèi)別不存在或已經(jīng)被刪除!"
                                exit Function
                            else    
                                set rs=conn.execute("select ClassID from ArticleClass where ClassName='"& sClassName &"' and ClassID<>"& nClassID &"and ParentID="& nParentID)    
                                if not rs.eof then                '類(lèi)名重復(fù)
                                    FEditCheck=1
                                    ErrorStr="類(lèi)名重復(fù)!"
                                    exit Function
                                end if
                                set rs=nothing
                            end if
                            set temprs=nothing
                        end if
                    end if
                end if
            End Function

            Public Sub SEdit()        '類(lèi)別修改
                sql="update ArticleClass set ClassName='"& sClassName &"',FilePath='"& sFilePath &"' where ClassID="& nClassID
                conn.execute(sql)
            End Sub

            Public Function FDeleteCheck()    '類(lèi)別刪除檢查函數(shù),結(jié)果為0表示通過(guò)檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫(xiě)入錯(cuò)誤變量ErrorStr
                FDeleteCheck=0                '這里刪除沒(méi)有寫(xiě)級(jí)聯(lián)刪除文章部分的代碼,刪除時(shí)應(yīng)該級(jí)聯(lián)刪除
                if nClassID="" then
                    FDeleteCheck=1
                    ErrorStr="要?jiǎng)h除的類(lèi)別id不能為空!"
                    exit Function
                else
                    set rs=conn.execute("select Child from ArticleClass where ClassID="& nClassID)
                    if rs.bof and rs.eof then
                        FDeleteCheck=1
                        ErrorStr="類(lèi)別不存在或者已經(jīng)被刪除!"
                        exit Function
                    else
                        if trim(rs("Child"))>0 then
                            FDeleteCheck=1
                            ErrorStr="該類(lèi)別含有子類(lèi)別,請(qǐng)刪除其子類(lèi)別后再進(jìn)行刪除本類(lèi)別的操作!"
                            exit Function
                        end if
                    end if
                end if
            End Function

            Public Sub SDelete()
                if nDepth>0 then            '修改父id孩子數(shù)
                    conn.execute("update ArticleClass set child=child-1 where child>0 and ClassID=" & nParentID)
                end if
                sql="delete from ArticleClass where ClassID="& nClassID
                conn.execute(sql)
            End Sub

            Public Function FErrStr()
                FErrStr=ErrorStr    
            End Function

        End Class
        %>

        核心js代碼 
        代碼如下:
        var xmlHttp; //定義一個(gè)全局變量
        var currentID=1;//設(shè)置當(dāng)前選中ID,如果此ID不存在則會(huì)發(fā)生js錯(cuò)誤
        //類(lèi)別顯示主函數(shù)
        //cid--子類(lèi)別所在層id
        //id --類(lèi)別id
        //pid--[+]和[-]圖標(biāo)id
        //fid--類(lèi)別圖標(biāo)id
        function DivDisplay(cid,id,pid,fid)
        {
            if (GetId(cid).style.display=='')    //子類(lèi)別不顯示時(shí)圖標(biāo)顯示控制
            {
                GetId(cid).style.display='none';
                GetId(pid).src = 'images/closed.gif';
                GetId(fid).src = 'images/folder.gif';
            }
            else        //展開(kāi)子類(lèi)別時(shí)的操作
            {
                GetId(cid).style.display='';
                GetId(pid).src = 'images/opened.gif';
                GetId(fid).src = 'images/folderopen.gif';
                if (GetId(cid).innerHTML==''||GetId(cid).innerHTML=='正在提交數(shù)據(jù)...')
                {
                    GetId(cid).innerHTML='';
                    ShowChild(cid,id);        //調(diào)用顯示子類(lèi)別函數(shù)
                }
            }
        }
        //與上一個(gè)函數(shù)作用相同,只作用在最后一個(gè)類(lèi)別
        function DivDisplay2(cid,id,pid,fid)
        {
            if (GetId(cid).style.display=='')
            {
                GetId(cid).style.display='none';
                GetId(pid).src = 'images/lastclosed.gif';
                GetId(fid).src = 'images/folder.gif';
            }
            else
            {
                GetId(cid).style.display='';
                GetId(pid).src = 'images/lastopen.gif';
                GetId(fid).src = 'images/folderopen.gif';
                if (GetId(cid).innerHTML==''||GetId(cid).innerHTML=='正在提交數(shù)據(jù)...')
                {
                    GetId(cid).innerHTML='';
                    ShowChild(cid,id);
                }
            }
        }
        //類(lèi)別添加函數(shù)
        //id--類(lèi)別id
        function ClassAdd(id){
        if (GetId("p"+id).src.indexOf("last")>0){    //最后一個(gè)類(lèi)別時(shí)的添加操作
            if (!GetId("p"+id).onclick){
                GetId("p"+id).onclick=function (){DivDisplay2("c"+id,id,"p"+id,"f"+id);};    //為[+]和[-]添加單擊事件
                GetId("s"+id).ondblclick=function (){DivDisplay2("c"+id,id,"p"+id,"f"+id);};    //為顯示類(lèi)別文字的span添加雙擊事件
                GetId("p"+id).src = 'images/lastopen.gif';
                }
            }
        else{
            if (!GetId("p"+id).onclick){    //不為最后一個(gè)類(lèi)別的添加操作
                GetId("p"+id).onclick=function (){DivDisplay("c"+id,id,"p"+id,"f"+id);};
                GetId("s"+id).ondblclick=function (){DivDisplay("c"+id,id,"p"+id,"f"+id);};
                GetId("p"+id).src = 'images/opened.gif';
                }
            }
        GetId("c"+id).style.display='';
        ShowChild("c"+id,id);
        }
        //類(lèi)別修改函數(shù)
        function ClassEdit(id,classname){
        GetId("s"+id).innerHTML=classname;
        }
        //有多個(gè)子類(lèi)別的類(lèi)別的刪除函數(shù)
        function ClassDel(id){
        ShowChild("c"+id,id);
        CurrentSelect(currentID,id)
        BrowseRight(id);
        }
        //只有一個(gè)子類(lèi)別的類(lèi)別的刪除函數(shù)
        function ClassDel1(id){
        if (GetId("p"+id).src.indexOf("last")>0){        //當(dāng)類(lèi)別是當(dāng)前類(lèi)別的最后一個(gè)類(lèi)別時(shí)
            GetId("p"+id).style.cursor="cursor";        //設(shè)置圖標(biāo)的鼠標(biāo)經(jīng)過(guò)樣式
            GetId("p"+id).onclick=function (){};        //因?yàn)橹挥幸粋€(gè)子類(lèi)別刪除后就不再有子類(lèi)別,故將圖標(biāo)單擊事件修改為空函數(shù)
            GetId("s"+id).ondblclick=function (){};        //同上
            GetId("p"+id).src = 'images/lastnochild.gif';    //圖標(biāo)設(shè)置
            }
        else{
            GetId("p"+id).style.cursor="cursor";        //非最后一個(gè)類(lèi)別的刪除操作
            GetId("p"+id).onclick=function (){};
            GetId("s"+id).ondblclick=function (){};
            GetId("p"+id).src = 'images/nofollow2.gif';        //這里的圖標(biāo)設(shè)置與前面不一樣
            }
        ShowChild("c"+id,id);
        CurrentSelect(currentID,id);
        BrowseRight(id);
        }
        //向右邊框架傳遞參數(shù)
        function BrowseRight(id){
        CurrentSelect(currentID,id);
        top.ContentFrame.location="../ArticleMain.asp?ClassID="+ id;
        }
        //設(shè)置類(lèi)別選中狀態(tài)的函數(shù)
        function CurrentSelect(oldid,newid){
        currentID=newid;
        document.getElementById("s"+oldid).style.backgroundColor="white";
        document.getElementById("s"+currentID).style.backgroundColor="#C0C0E9";
        }
        //創(chuàng)建XMLHttpRequest對(duì)象
        function CreateXMLHttpRequest()
        {
            if (window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
        //Ajax處理函數(shù)
        //id,層id
        //rid,數(shù)據(jù)在表中的id
        function ShowChild(cid,id)
        {
            CreateXMLHttpRequest();
            if(xmlHttp)
            {
                xmlHttp.open('POST','child.asp',true);
                xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                var SendData = 'id='+id;
                xmlHttp.send(SendData);
                xmlHttp.onreadystatechange=function()
                {
                   if(xmlHttp.readyState==4)
                   {
                     if(xmlHttp.status==200)
                     {
                        GetId(cid).innerHTML = xmlHttp.responseText;
                     }
                     else
                     {
                        GetId(cid).innerHTML='出錯(cuò):'+xmlHttp.statusText;
                     }
                   }
                   else
                   {
                        GetId(cid).innerHTML="正在提交數(shù)據(jù)...";
                    }
                  }

             }
             else
             {
                 GetId(cid).innerHTML='抱歉,您的瀏覽器不支持XMLHttpRequest,請(qǐng)使用IE6以上版本!';
             }

        }
        //取得頁(yè)面對(duì)象
        //id,層id
        function GetId(id)
        {
            return document.getElementById(id);

        聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼

        ajax+asp無(wú)限級(jí)分類(lèi)樹(shù)型結(jié)構(gòu)的代碼: 代碼如下:<% '數(shù)據(jù)庫(kù)字段為類(lèi)屬性,添加、刪除、修改、操作檢查等函數(shù)為類(lèi)的方法 Class Cls_Leibie Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定義私有變量(
        推薦度:
        標(biāo)簽: 代碼 無(wú)限 代碼代碼
        • 熱門(mén)焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門(mén)推薦

        專題
        Top
        主站蜘蛛池模板: 国产AV无码专区亚洲AV琪琪| 国产精一品亚洲二区在线播放| 在线涩涩免费观看国产精品| 国产精品亚洲二区在线观看| 成人A级毛片免费观看AV网站| 丁香花在线视频观看免费| 黄页视频在线观看免费| 欧洲 亚洲 国产图片综合| 亚洲国产成人久久精品动漫| 亚洲av成人一区二区三区在线观看| 免费无码又爽又刺激聊天APP| 日本一区二区免费看| 久久WWW免费人成—看片| 免费大片av手机看片高清| 亚洲免费综合色在线视频| 精品亚洲国产成人| 亚洲国产视频网站| 久久精品国产亚洲AV大全| 亚洲av伊人久久综合密臀性色 | 亚洲最新在线视频| 亚洲av不卡一区二区三区| 国产亚洲精品a在线无码| 国产av无码专区亚洲国产精品| 免费人成网站在线高清| 日韩免费观看的一级毛片| 成年人免费网站在线观看| 中文在线免费观看| 国产精品免费在线播放| jzzjzz免费观看大片免费| 又黄又大的激情视频在线观看免费视频社区在线 | 亚洲日韩人妻第一页| 一本色道久久88亚洲综合| 免费一级毛片清高播放| 免费v片在线观看品善网| 高清在线亚洲精品国产二区| 内射无码专区久久亚洲| 亚洲成AV人网址| 亚洲最大AV网站在线观看| 亚洲理论电影在线观看| 亚洲av福利无码无一区二区| 亚洲一区二区在线视频|