網站建設是指使用標識語言(markup language),通過一系列設計、建模、和執行的過程將電子格式的信息通過互聯網傳輸,最終以圖形用戶界面(GUI)的形式被用戶所瀏覽。簡單來說,網頁設計的目的就是產生網站。簡單的信息如文字,圖片(GIF,JPEG,PNG)和表格,都可以通過使超文件標示語言、可擴展超文本標記語言等標示語言放置到網站頁面上。 利用ACCESS創建數據庫listBase.mdb: 數據表:listTable 數據字段:listId listName listInfo parentId 連接方法: <% dim sConn,sConnStr,sSql sConnStr="DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("listBase.mdb") set sConn=server.createobject("adodb.connection") sConn.open sConnStr %> 把以上代碼保存成文件:initialize.asp 下面這段程序代碼是用來顯示目錄樹用的,保存成文件:inc.asp
<!--#include file="initialize.asp"--> <script language=jscript> <!-- //此函數用來顯示與關閉它的子菜單的,并切換其前面的小圖片 function showMenu(menuObj,isSub){ if(menuObj.style.display=="none"){ menuObj.style.display=""; if(isSub==1){ event.srcElement.src="images/open.gif"; } } else{ menuObj.style.display="none"; if(isSub==1){ event.srcElement.src="http://www.okasp.com/techinfo/images/close.gif"; } } } //--> </script> <!--下面這段藍色的區域,是設置目錄樹的根,其中的內容非數據內的數據,數據庫內的數據都附著在它的下面//--> <% response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13)) response.write("<tr>" & chr(13)&"<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>") response.write("<tr>" & chr(13) & "<td width='18' ><img src='http://www.okasp.com/techinfo/images/root.gif' onclick='jscript:showMenu(subMenu0,0)' style='cursor:hand' alt='不可修改'></td>" & chr(13) & "<td width='100' class='menuPro' id='listName0'>根節點</td>" & chr(13)) response.write("<td width='40' class='menuFont' align='center' style='cursor:hand' onclick=""jscript:showForm('add',0)"">添加</td>" & chr(13)) response.write("<td width='40' class='menuFont' align='center' onclick=''></td>" & chr(13)) response.write("<td> </td></tr></table></td></tr>" & chr(13)) response.write("<tr id='subMenu0'>" & chr(13) & "<td colspan='2'>" & chr(13)) '此處調用顯示目錄樹的遞歸函數 listChild(0) response.write("</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13)) '下面代碼為顯示目錄樹最關鍵的函數,使用了遞歸方法(很多象這樣類型的都是用遞歸來做的。) function listChild(id) dim sRec,sSql,sNum,sTmp set sRec=server.createobject("adodb.recordset") sSql="select listId,listName,listInfo,parentId from listTable where parentId=" & id sRec.open sSql,sConn,3,1 if not sRec.eof then sNum=1 response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13)) while not sRec.eof sTmp=sConn.execute("select count(listId) as countSub from listTable where parentId=" & sRec("listId")) if sTmp("countSub")>0 then response.write("<tr>" & chr(13)) if sNum=sRec.recordcount then response.write("<td width='18' valign='top'><img src='http://www.okasp.com/techinfo/images/angel.gif'></td>" & chr(13)) else response.write("<td width='18' background='images/eline.gif' valign='top'><img src='http://www.okasp.com/techinfo/images/t.gif' ></td>" & chr(13)) end if response.write("<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13)) response.write("<tr>" & chr(13) & "<td width='118' class='menuPro' id='listName" & sRec("listId") & "'><img id='img" & sRec("listId") & "' style='cursor:hand' src='http://www.okasp.com/techinfo/images/close.gif' align='absMiddle' onclick='jscript:showMenu(subMenu" & sRec("listId") & ",1)' alt='" & sRec("listInfo") & "'>" & server.HTMLEncode(sRec("listName")) & "</td>" & chr(13) & "<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('add'," & sRec("listId") & ")"">添加</div></td><td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('edit'," & sRec("listId") & ")"">編輯</div></td>" & chr(13)) response.write("<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:window.location='disp.asp?disp=del&parentId=" & sRec("listId") & "'"">刪除 </div></td>" & chr(13) & "<td> </td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13) & "</td>" & chr(13) & "</tr>" & chr(13)) response.write("<tr id='subMenu" & sRec("listId") &"' style='display:none'>") if sNum=sRec.recordcount then response.write("<td width='18' valign='top'") response.write("<img src='http://www.okasp.com/techinfo/images/angel.gif' >") response.write("</td>" & chr(13)) else response.write("<td width='18' valign='top' background='images/eline.gif'>") response.write("</td>" & chr(13)) end if response.write("<td>" & chr(13)) listChild(sRec("listid")) response.write("</td>" & chr(13) & "</tr>" & chr(13)) else response.write("<tr>" & chr(13)) if sNum=sRec.recordcount then response.write("<td width='18' valign='top'><img src='http://www.okasp.com/techinfo/images/angel.gif'></td>" & chr(13)) else response.write("<td width='18' background='images/eline.gif' valign='top'><img src='http://www.okasp.com/techinfo/images/t.gif' ></td>" & chr(13)) end if response.write("<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13)) response.write("<tr>" & chr(13) & "<td width='118' class='menuPro' id='listName" & sRec("listId") & "'><img id='img" & sRec("listId") & "' src='http://www.okasp.com/techinfo/images/file.gif' align='absMiddle' alt='" & sRec("listInfo") & "'>" & server.HTMLEncode(sRec("listName")) & "</td>" & chr(13) & "<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('add'," & sRec("listId") & ")"">添加</div></td><td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('edit'," & sRec("listId") & ")"">編輯</div></td>" & chr(13)) response.write("<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:window.location='disp.asp?disp=del&parentId=" & sRec("listId") & "'"">刪除</div></td>" & chr(13) & "<td> </td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13) & "</td>" & chr(13) & "</tr>" & chr(13)) end if sRec.movenext sNum=sNum+1 wend response.write("</table>" & chr(13)) end if sRec.close '關閉記錄集 set sRec=nothing '關閉記錄集 end function sConn.close '關閉數據庫鏈接 set sConn=nothing '關閉數據庫鏈接 %> 下面這是調用頁代碼,保存成index.asp
<%@LANGUAGE='VBSCRIPT' CODEPAGE='936'%> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> <title>目錄樹</title> <script language='JavaScript' type='text/JavaScript'> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=='Netscape')&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); //--> </script> <script language="JScript"> <!-- //此函數設置處理表單的內容 //比如添加時,表單為空,并顯示為什么節點添加子節點 //比如修改時,表單內為相應節點的內容,并顯示在修改什么節點 function showForm(disp,parentId){ addNodeDiv.style.display=""; document.all.addNodeForm.disp.value=disp; document.all.addNodeForm.parentId.value=parentId; if(disp=="edit"){ document.all.addNodeForm.listInfo.value=eval("img"+parentId+".alt"); document.all.addNodeForm.listName.value=eval("listName"+parentId+".innerText"); infoValue.innerText="編輯["+eval("listName"+parentId+".innerText")+"]節點"; } else{ document.all.addNodeForm.listInfo.value=""; document.all.addNodeForm.listName.value=""; infoValue.innerText="給節點["+eval("listName"+parentId+".innerText")+"]添加子節點"; } } <!--這棕色部分為移動表單代碼,可以不要。//--> function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; }function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01 //Copyright 1998 Macromedia, Inc. All rights reserved. var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers; var NS6=(!IE&&document.getElementById), NS=(NS4 NS6); if (!IE && !NS) return false; retVal = true; if(IE && event) event.returnValue = true; if (MM_dragLayer.arguments.length > 1) { curDrag = MM_findObj(objName); if (!curDrag) return false; if (!document.allLayers) { document.allLayers = new Array(); with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i]; for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers) with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j]; } else { if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div"); for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];} for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i]; } } curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT; curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT; curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront; curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS; curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS; curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex; curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft; if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft; curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop; if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop; curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU; curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD; curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS! document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP); } else { var theEvent = ((NS)?objName.type:event.type); if (theEvent == 'mousedown') { var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft; var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop; var maxDragZ=null; document.MM_maxZ = 0; for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i]; var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex); if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ; var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1); if (aLayer.MM_dragOk != null && isVisible) with (aLayer) { var parentL=0; var parentT=0; if (NS6) { parentLayer = aLayer.parentNode; while (parentLayer != null && parentLayer.style.position) { parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop); parentLayer = parentLayer.parentNode; } } else if (IE) { parentLayer = aLayer.parentElement; while (parentLayer != null && parentLayer.style.position) { parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop; parentLayer = parentLayer.parentElement; } } var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft); var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop); if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0; var tmpW = MM_hWidth; if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth); var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight); if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } } if (curDrag) { document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE); curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft; curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop; if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0; MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop; document.MM_curDrag = curDrag; curDrag.MM_SNAPPED=false; if(curDrag.MM_toFront) { eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1'); if (!curDrag.MM_dropBack) document.MM_maxZ++; } retVal = false; if(!NS4&&!NS6) event.returnValue = false; } } else if (theEvent == 'mousemove') { if (document.MM_curDrag) with (document.MM_curDrag) { var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft; var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop; newLeft = mouseX-MM_oldX; newTop = mouseY-MM_oldY; if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL); if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR); if (MM_bT!=null) newTop = Math.max(newTop ,MM_bT); if (MM_bB!=null) newTop = Math.min(newTop ,MM_bB); MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT; if (NS4) {left = newLeft; top = newTop;} else if (NS6){style.left = newLeft; style.top = newTop;} else {style.pixelLeft = newLeft; style.pixelTop = newTop;} if (MM_dragJS) eval(MM_dragJS); retVal = false; if(!NS) event.returnValue = false; } } else if (theEvent == 'mouseup') { document.onmousemove = null; if (NS) document.releaseEvents(Event.MOUSEMOVE); if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS if (document.MM_curDrag) with (document.MM_curDrag) { if (typeof MM_targL =='number' && typeof MM_targT == 'number' && (Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+ Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) { if (NS4) {left = MM_targL; top = MM_targT;} else if (NS6) {style.left = MM_targL; style.top = MM_targT;} else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;} MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; } if (MM_everyTime MM_SNAPPED) eval(MM_dropJS); if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;} retVal = false; if(!NS) event.returnValue = false; } document.MM_curDrag = null; } if (NS) document.routeEvent(objName); } return retVal; } //--> </script> <link href='css/css.css' rel='stylesheet' type='text/css'> </head><body bgcolor="#4A8CCE" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <div id="addNodeDiv" style="position:absolute; left:400; top:300; width:300; height:135; z-index:1;display:none;" class="formDiv" onMouseDown="MM_dragLayer('addNodeDiv','',1,1,300,30,true,false,-1,-1,-1,-1,false,false,0,'',false,'')"> <form action="disp.asp" method="get" name="addNodeForm" id="addNodeForm"> <table width="300" border="0" cellspacing="0" cellpadding="3"> <tr style="cursor:hand"> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><div id="infoValue" class="menuFont"></div></td> <td><div align="right"> <input name="parentId" type="hidden" id="parentId"> <input name="disp" type="hidden" id="disp"> <img src="http://www.okasp.com/techinfo/images/close2.gif" alt="點擊關閉" width="13" height="13" style="cursor:hand" onclick="jscript:addNodeDiv.style.display='none';"></div></td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="70" class="menuFont"> <div align="right">節點名稱:</div></td> <td width="120"><input name="listName" type="text" class="text1" id="listName"></td> <td class="menuFont">10個字符BR> </tr> <tr> <td width="70"> <div align="right" class="menuFont">節點說明:</div></td> <td><textarea name="listInfo" cols="19" rows="3" class="text1" id="listInfo"></textarea></td> <td class="menuFont">50個字符</td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="80"> </td> <td width="40"> <input name="SubmitBut" type="submit" class="DivBut" id="SubmitBut" value="提交" onclick="jscript:addNodeForm.submit();this.disabled='disabled'"> </td> <td width="10"> </td> <td width="40"> <input name="cancelBut" type="button" class="DivBut" id="cancelBut" onclick="jscript:addNodeDiv.style.display='none';" value="取消"> </td> <td> </td> </tr> </table></td> <td> </td> </tr> </table> </td> </tr> </table> </form> </div> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <!--此處為包含文件//--> <div id="Layer1" class="treeDiv"> <!--#include file="inc.asp"--> </div> </td> </tr> </table> </body> </html>下面是提交信息處理頁的代碼,保存為disp.asp <!--#include file="initialize.asp"--> <% function checkstr(str) str=replace(str,"'","''",1,-1,1) checkstr=str end function
dim disp,parentId,listName,listInfo disp=request.QueryString("disp") parentId=request.QueryString("parentId") select case disp case "add" listName=checkstr(left(request.QueryString("listName"),10)) listInfo=checkstr(left(request.QueryString("listInfo"),50)) if listName="" then listName="空白節點" if listInfo="" then ListInfo="此節點在添加入未填寫內容" sSql="insert into listTable (listName,listInfo,parentId) values('" & listName & "','" & listInfo & "'," & parentId & ")" case "edit" listName=checkstr(left(request.QueryString("listName"),10)) listInfo=checkstr(left(request.QueryString("listInfo"),50)) if listName="" then listName="空白節點" if listInfo="" then listInfo="此節點在添加入未填寫內容" sSql="update listTable set listName='" & listName & "',listInfo='" & listInfo & "' where listId=" & parentId case "del" sSql="delete from listTable where listId=" & parentId & " or parentId=" & parentId end select sConn.execute sSql,,1 response.redirect("index.asp") %>以上代碼保存成的文件放在同一目錄下面(在這里我們稱為根目錄)。 在根目錄下新建一個CSS目錄. 下面為CSS定義,保存成css.css文件,放在CSS目錄下。注:有一兩個樣式是不要的,我沒刪 .menuPro { border-top: 1px dotted #A5BBE0; border-right: 1px dotted #31548E; border-bottom: 1px dotted #31548E; border-left: 1px dotted #A5BBE0; overflow: visible; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; } .menuGro { border-top: 2px outset #31548E; border-right: 2px outset #A5BBE0; border-bottom: 2px outset #A5BBE0; border-left: 2px outset #31548E; overflow: visible; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; } .menuFont { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; } .showDiv { display:''; } .hiddenDiv { display:none; } .treeDiv { background-color: #A8D5EA; height: 100%; width: 100%; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-style: inset; border-right-style: inset; border-bottom-style: inset; border-left-style: inset; border-top-color: #3680C9; border-right-color: #BCD5ED; border-bottom-color: #BCD5ED; border-left-color: #3680C9; overflow: auto; padding: 20px; } body { overflow: hidden; } .formDiv { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; font-weight: normal; background-color: #7ABDDE; height: 200px; width: 300px; border-top: 1px outset #B9DCFF; border-right: 1px outset #004488; border-bottom: 1px outset #004488; border-left: 1px outset #B9DCFF; overflow: hidden; } .text1 { width: 160px; } .DivBut { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; font-weight: normal; background-color: #3399CC; height: 20px; width: 40px; border: 1px outset; } 另在根目錄下建一個IMAGES目錄。用來放那些文件夾樣子的小圖。 打包下載[請使用WINRAR3.0解壓]:小圖片
(出處:六月海設計)大多數人在上網的時候,都會瀏覽網頁提供給我們的信息。
|