三层动态下拉菜单的例子

写了一个三层动态读取文件夹的下拉菜单的例子,供大家参考!

 1   
 2'得到文件夹路径。注意设置文件名字   
 3urlpath=server.mappath("\book")   
 4set fsoBrowse=CreateObject("Scripting.FileSystemObject")   
 5  
 6'设置文件夹路径   
 7if Request("path")="" then   
 8lpath=urlpath&"\"   
 9else   
10lpath=Request("path")&"\"   
11end if   
 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<meta content="NO-CACHE" http-equiv="PRAGMA"/>
 5<title>中国国际航空公司</title>
 6<link href="news.css" rel="stylesheet"/>
 7<script language="JavaScript1.2">   
 8NS4 = (document.layers) ? 1 : 0;   
 9IE4 = (document.all) ? 1 : 0;   
10ver4 = (NS4 || IE4) ? 1 : 0;   
11  
12if (ver4) {   
13with (document) {   
14write("<STYLE TYPE='text/css'>");   
15if (NS4) {   
16write(".parent {position:absolute; visibility:visible}");   
17write(".child {position:absolute; visibility:visible}");   
18write(".regular {position:absolute; visibility:visible}")   
19}   
20else {   
21write(".child {display:none}")   
22}   
23write("</STYLE>");   
24}   
25}   
26  
27function getIndex(el) {   
28ind = null;   
29for (i=0; i<document.layers.length; i++) {   
30whichEl = document.layers[i];   
31if (whichEl.id == el) {   
32ind = i;   
33break;   
34}   
35}   
36return ind;   
37}   
38  
39function arrange() {   
40nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;   
41for (i=firstInd+1; i<document.layers.length; i++) {   
42whichEl = document.layers[i];   
43if (whichEl.visibility != "hide") {   
44whichEl.pageY = nextY;   
45nextY += whichEl.document.height;   
46}   
47}   
48}   
49  
50function initIt(){   
51if (!ver4) return;   
52if (NS4) {   
53for (i=0; i<document.layers.length; i++) {   
54whichEl = document.layers[i];   
55if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";   
56}   
57arrange();   
58}   
59else {   
60divColl = document.all.tags("DIV");   
61for (i=0; i<divColl.length; i++) {   
62whichEl = divColl(i);   
63if (whichEl.className == "child") whichEl.style.display = "none";   
64}   
65}   
66}   
67  
68function expandIt(el) {   
69if (!ver4) return;   
70if (IE4) {   
71whichEl = eval(el + "Child");   
72if (whichEl.style.display == "none") {   
73whichEl.style.display = "block";   
74}   
75else {   
76whichEl.style.display = "none";   
77}   
78}   
79else {   
80whichEl = eval("document." + el + "Child");   
81if (whichEl.visibility == "hide") {   
82whichEl.visibility = "show";   
83}   
84else {   
85whichEl.visibility = "hide";   
86}   
87arrange();   
88}   
89}   
90  
91onload = initIt;   
92  
93</script>
94</head>
95<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
96<table align="left" border="0" cellpadding="0" cellspacing="0" width="248">
97<tr>
98<td>   

'处理第一层文件目录
dim theFolder,theSubFolders
if fsoBrowse.FolderExists(lpath)then
Set theFolder=fsoBrowse.GetFolder(lpath)
Set theSubFolders=theFolder.SubFolders

'循环输出第一层文件
i=1
For Each x In theSubFolders
k="KB"&amp;i
Parent=k&amp;"Parent"
i=i+1

1<div class="parent" id="```
2=Parent
3```"> <a href="#" onclick="expandIt('```
4=k
5```'); return false"><img border="0" height="16" src="i_option.gif" width="20"/>```
6=x.Name
7```</a></div>   

'处理第二层文件
onepath=lpath&amp;x.Name&amp;""
if fsoBrowse.FolderExists(onepath) then
Set ChildtheFolder=fsoBrowse.GetFolder(onepath)
Set ChildtheSubFolders=ChildtheFolder.SubFolders
Child=k&amp;"Child"

1<div class="child" id="```
2=Child
3```">   

'循环输出第二层文件
m=1
For Each y In ChildtheSubFolders
k="KB"&amp;i&amp;m
m=m+1

1   <img height="13" src="filebox.gif" width="19"/><a href="#" onclick="expandIt('```
2=k
3```'); return false">```
4=y.Name
5```</a><br/>   

'处理第三层文件
twopath=onepath&amp;y.Name&amp;""
if fsoBrowse.FolderExists(twopath) then
Set gtheFolder=fsoBrowse.GetFolder(twopath)
Set gtheSubFolders=gtheFolder.SubFolders

Child=k&amp;"Child"

1<div class="child" id="```
2=Child
3```">   

'循环输出第三层文件
For Each z In gtheSubFolders

1      <img height="13" src="filebox.gif" width="19"/>```
2=z.Name
3```<br/>   

Next

1</div>   

end if

Next

1</div>   

end if

Next
end if

1</td>
2</tr>
3</table>
4</body>
5</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus