作者: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();" style="cursor:hand;" id="menuSwitch" align="center">
<img id="Image1" src="images/ArrowClose.gif" border="0" />
</td>
</tr>
</table>
以上功能並不完善,只能起到拋磚引玉的作用,歡迎網友與我交流.