< !-- #include virtual='Include/database.asp' --> < % set rs=Server.CreateObject("ADODB.RecordSet")
sql="SELECT menu_name, menu_link, menu_bgcolor, menu_color,id FROM enter_individual WHERE (parent_id = (SELECT id FROM enter_individual WHERE menu_flag = 'root' )) " '查詢得到根節點 rs.Open sql,conn,1,1 Response.Write "< table width=100% border=0 cellspacing=1 cellpadding=0 align=center>< tr bgcolor=#3399CC valign=bottom align=center>" sumnum=rs.RecordCount myArray=rs.GetRows() rs.Close () widd=780/sumnum '從一級子菜單數目判斷彈出菜單x坐標的遞增像素 dim i i=0 defaultbgcolor="#3399cc" '指定默認底色 defaultcolor="#ffffff" '指定默認字體顏色 defaultlink="#" '指定默認鏈接 posit_x=0 'x位置 flag=1 '標志,作為菜單彈出方向 1表示向右,0表示向左 'Response.Write myArray(4,6) while i Response.Write "< td height=20 bgcolor="&myArray(2,i)&" width="&widd&">< a href="&myArray(1,i)&" onmouseover=java script:a"&myArray(4,i)&".style.display='block' onmouseout=java script:a"&myArray(4,i)&".style.display='none' >< font color="&myArray(3,i)&" >"&myArray(0,i)&"< /a>< /td>" '-----------------------------------------------
i=i+1 Wend Response.Write "< /tr>< /table>"
i=0 while i posit_y=100 'y位置回到原位
If i>=(sumnum/2) Then '如果菜單進入右半部分,則彈出轉向 flag=0 End If
'調用GetSubMenu 函數 設置該項一級菜單的下級菜單,以myArray(4,i) 即菜單id作為下級菜單所在div 的id
GetSubMenu myArray(4,i),posit_x,posit_y posit_x=posit_x+widd '下一個一級菜單的子菜單的 x坐標值增加一個單位 i=i+1
Wend
'使用遞規算法的到下級菜單的函數 'parent_id 父 id; posit_x 彈出層的左邊位置; posit_y 彈出層的離上面位置;
Function GetSubMenu(parent_id,posit_x,posit_y) dim myArray dim sumnum dim i
'查詢子菜單的下級菜單 sql="SELECT menu_name, menu_link, menu_bgcolor, menu_color,id FROM enter_individual WHERE parent_id = "&parent_id&" AND user_id = '"&userid&"'" rs.Open sql,conn,1,1
'如果下級菜單不存在,則層數減一 ,關閉數據庫鏈接,建立一個以父id為div id的空層,然后返回 If rs.EOF=true Then level=level-1 rs.Close () 'Response.Write parent_id Response.Write "< div id='a"&parent_id&"' style='position: absolute; top: 4; left: -1; display: none; width: 0; height: 0'>< /div>" Else
'如果存在取到數據庫數據,并調用SetSubMenu顯示菜單 sumnum=rs.RecordCount myArray=rs.GetRows() rs.Close () SetSubMenu myArray,sumnum,parent_id,posit_x,posit_y
'對數據進行循環,遞規調用GetSubMenu i=0 while i< sumnum posit_y=posit_y*1+20 '遞規一次posit_y 加一個單位, if level=0 Then '如果級數減到0 則回到1 level=1 End If 'If flag=1 Then 'GetSubMenu myArray(4,i),posit_x+level*widd,posit_y-level*20 '遞規調用GetSubMenu x,y坐標延伸 level 個單位 'End If If flag=0 Then GetSubMenu myArray(4,i),posit_x-level*widd,posit_y-level*20 '遞規調用GetSubMenu x,y坐標延伸 level 個單位 Else GetSubMenu myArray(4,i),posit_x+level*widd,posit_y-level*20 '遞規調用GetSubMenu x,y坐標延伸 level 個單位 End If
i=i+1 Wend End If
End Function
'設置子菜單函數 'myArray 菜單數據 ,sumnum 數組大小 ,parent_id 層的id ; 'posit_x 彈出層的左邊位置; posit_y 彈出層的離上面位置;
Function SetSubMenu (myArray,sumnum,parent_id,posit_x,posit_y) dim i parent_id="a"&parent_id '父菜單id前面加上a 作為層的id hh=sumnum*20 '數組大小乘以20作為層的高度 Response.Write "< DIV onmouseover=java script:"&parent_id&".style.display='block' onmouseout=java script:"&parent_id&".style.display='none' ID='"&parent_id&"' STYLE='position: absolute; top:"&posit_y&"; left:"&posit_x&"; height:"&hh*1&"; width: "&widd&"; display:none;vertical-align: top'>< table width=100% border=0 cellspacing=1 cellpadding=0 >" i=0 While i
myArray(0,i)=Trim(myArray(0,i)) myArray(1,i)=Trim(myArray(1,i)) myArray(2,i)=Trim(myArray(2,i)) myArray(3,i)=Trim(myArray(3,i))
If myArray(2,i)="" Then myArray(2,i)=defaultbgcolor End If
If myArray(3,i)="" Then myArray(3,i)=defaultcolor End If
If myArray(1,i)="" Then myArray(1,i)=defaultlink End If
Response.Write "< tr align=center >< td width=100% height=20 bgcolor="&myArray(2,i)&" onmouseover=java script:"&parent_id&".style.display='block';a"&myArray(4,i)&".style.display='block' onmouseout=java script:a"&myArray(4,i)&".style.display='none'>< a href='"&myArray(1,i)&"'>< font color="&myArray(3,i)&" >"&myArray(0,i)&"< /font>< /a>< /td>< /tr>"
i=i+1 Wend
Response.Write " < /table> < /DIV>"
End Function
Set rs=nothing conn.Close () Set conn=nothing % >
|