當你在做一個仿windows程式的頂部菜單架構的時候,在asp.net中你可能會使用兩個frame,一個frame在上面用來放菜單一個frame在下面用來方菜單點擊後開啟的頁面.頁面實現很簡單,單啟動並執行時候你就發現放菜單的那個frame將菜單的下列菜單在擋住根本伸不到下面的frame中.解決被擋住的問題是不能使用frame,做法是在一個單獨的asp.net頁面中放一個menu 和一個iframe,嗯,至此下拉式功能表不會被擋住,單又有一個新問題出來了,那就是iframe的高度問題,如果強制寫死它的高度,那根本是不可接受的.如果解決?解決的辦法就是使用javascript 在body的onload和onsized事件中對iframe的高度進行控制.下面代碼解決上述的問題.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題頁</title>
<script language="javascript" type="text/javascript">
function aaaaa()
{
document.getElementById('f1').height=document.body.clientHeight-80;
}
</script>
</head>
<body onload="aaaaa()" onresize="aaaaa()" scroll="no" style="margin: 0">
<form id="form1" runat="server">
<table>
<tr>
<td height="80">
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" BackColor="#E3EAEB"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666"
StaticSubMenuIndent="10px">
<StaticSelectedStyle BackColor="#1C5E55" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#666666" ForeColor="White" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<DynamicSelectedStyle BackColor="#1C5E55" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
<Items>
<asp:MenuItem Text="建立項1" Value="建立項1">
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項">
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
<asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="建立項2" Value="建立項2"></asp:MenuItem>
<asp:MenuItem Text="建立項3" Value="建立項3"></asp:MenuItem>
</Items>
</asp:Menu>
</td>
</tr>
</table>
<iframe id="f1" scrolling="auto" width="100%" height="200" src="HTMLPage5.htm"></iframe>
</form>
</body>
</html>