您的位置:建站学院首页 >> 文章 >> asp技术 >> XML相关
用DHTML来模拟实现下拉菜单
  我在许多的网站上看到上面都有下拉菜单的,使得网站更栩栩如生了!象微软的主页,后来我想假如单用div和javascript是否也能实现了,通过几次实验也总于成功了,现在把自己想法告诉大家,希望大家网页也加上下拉菜单使网爷更生动.
以前DOS下编写应用程序都要面临着界面编写的,象菜单这些东西也要自己从头到尾都要自己编的,到了win时代,通过事件驱动我们就很容易编写了,何况菜单集成到系统里了,在IE下编写菜单也是基于通过捕获鼠标事件来响应菜单下拉和隐藏的,
我们首先要用表格来显示菜单条,
<body>
<table>
<tr>
<td height="9" width="100" align=center bgcolor="#33FFFF"

onmouseover="showmenu(menuwenxue)">menu1</td>
<td height="9" width="100" align=center bgcolor="#33FFFF"

onmouseover="showmenu(menuxuexi)">menu1</td>
<tr>
</table>

<div id="menuwenxue" style="position:absolute; width:90px; height:115px; z-index:1; left: 45px;

top: 75px; visibility: hidden" onmouseout="hidemenu(menuwenxue)">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"

onmouseout="hidemenu(menuwenxue)">
<tr>
<td height="10" class="menufont" onmouseover="showmenu(menuwenxue)"> </td>
</tr>
<tr>
<td height="28" align=center class="menufont" bgcolor=#ff00ff

onmouseover="showmenu(menuwenxue)"><a href="javascript:alert('menu1_item1')">menu1_item1</a></td>
</tr>
<tr>
<td height="31" align=center bgcolor=#ff00ff onmouseover="showmenu(menuwenxue)"><a

href="javascript:alert('menu1_item2')">menu1_item2</a></td>
</tr>
<tr>
<td height="30" align=center bgcolor=#ff00ff onmouseover="showmenu(menuwenxue)"><a

href="javascript:alert('menu1_item3')">menu1_item3</a></td>
</tr>
</table>
</div>
<div id="menuxuexi" style="position:absolute; width:90px; height:115px; z-index:1; left: 140px;

top: 75px; visibility: hidden" onmouseout="hidemenu(menuxuexi)">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"

onmouseout="hidemenu(menuxuexi)">
<tr>
<td height="10" onmouseover="showmenu(menuxuexi)"> </td>
</tr>
<tr>
<td height="27" align=center bgcolor=#ff00ff onmouseover="showmenu(menuxuexi)"><a

href="javascript:alert('menu2_item2')">menu2_item1</a></td>
</tr>
<tr>
<td height="31" align=center bgcolor=#ff00ff onmouseover="showmenu(menuxuexi)"><a

href="javascript:alert('menu2_item2')">menu2_item2</a></td>
</tr>
<tr>
<td height="30" align=center bgcolor=#ff00ff onmouseover="showmenu(menuxuexi)"><a

href="javascript:alert('menu2_item3')">menu2_item3</a></td>
</tr>
</table>

本内容共2页  首 页  上一页  下一页  尾 页  当前在第1

Google
 
Web www.cqxw.net