作者:DotSharp
我們在CSDN論壇上的左上角能夠看到導航欄的功能,下面就模擬該功能,利用JS在ASP.Net中作一個簡單的無刷新的左導航欄隱藏功能.
首先,作一個框架頁,我們取名 main.ASPx
<!-- main.ASPx 主要代碼 -->
<script>
document.write("<frameset rows='54,28,*,19' frameborder='NO' border='0' framespacing='0'>");
document.write("<frame src='title.ASPx' name='topFrame' scrolling='NO' noresize>");
document.write("<frame src='bar.ASPx' name='MainNaviFrame' scrolling='NO'>");
<!-- left.aspx是導航頁 ,menuswitch.ASPx是交互的按鈕頁 -->
document.write("<frameset name='forum' cols='150,8,*' frameborder='NO' border='0' framespacing='0'>");
document.write("<frame src='left.ASPx' name='LeftFrame' scrolling='auto'>");
document.write("<frame src='menuswitch.ASPx' name='SwichFrame' scrolling='No'>");
document.write("<frameset rows='100%,*' frameborder='NO' border='0' framespacing='0'>");
document.write("<frame src='' name='MainFrame' scrolling='no'>");
document.write("</frameset></frameset>");
document.write("<frame src='bottom.ASPx' name='BottomFrame' scrolling='No'></frameset>");
</script>
<!-- menuswitch.JS 主要代碼-->
var leftwin = true;
function changeWin()
{
if(leftwin == true)
{
parent.forum.cols = "0,8,*";
parent.SwichFrame.menuSwitch.innerHtml = "<a onclick='changeWin();' style='cursor:hand;'><img src='images/ArrowOpen.gif' border='0'></a>";
leftwin = false;
}
else
{
parent.forum.cols = "150,8,*";
parent.SwichFrame.menuSwitch.innerHtml = "<a onclick='changeWin();' style='cursor:hand;'><img src='images/ArrowClose.gif' border='0'></a>";
leftwin = true;
}
}
<!-- menuswitch.ASPx 主要代碼 -->
<table height="100%" cellSpacing="0" cellPadding="0" width="8" background="images/MiddleBg1.gif"
border="0">
<tr>
<td onclick="changeWin();" id="menuSwitch" align="center">
<img id="Image1" src="images/ArrowClose.gif" border="0" />
</td>
</tr>
</table>
以上功能並不完善,只能起到拋磚引玉的作用,歡迎網友與我交流.