·您的位置: 首页 » 资源教程 » 编程开发 » HTML、CSS » 用DHTML来模拟实现下拉菜单

用DHTML来模拟实现下拉菜单

类别: HTML、CSS教程  评论数:0 总得分:0
我在许多的网站上看到上面都有下拉菜单的,使得网站更栩栩如生了!象微软的主页,后来我想假如单用div和JAvascript是否也能实现了,通过几次实验也总于成功了,现在把自己想法告诉大家,希望大家网页也加上下拉菜单使网爷更生动.
以前DOS下编写应用程序都要面临着界面编写的,象菜单这些东西也要自己从头到尾都要自己编的,到了win时代,通过事件驱动我们就很容易编写了,何况菜单集成到系统里了,在IE下编写菜单也是基于通过捕获鼠标事件来响应菜单下拉和隐藏的,
我们首先要用表格来显示菜单条,
<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: 245px; 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)">&nbsp;</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: 340px; 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)">&nbsp;</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>
</div>
<Script language="JavaScript">
<!--
function showmenu(menu){
if(menushow)
menushow.style.visibility="hidden"
menushow=menu
menu.style.visibility="visible"
}
function hidemenu(menu){
menu.style.visibility="hidden"
}
function hideshow()
{
if(menushow)
menushow.style.visibility="hidden"
}
-->
</script>

-->
</script>
上面是我从调试代码上截下来的,要想得到好看的结果需要改变一下位子关系的,当然还要注意一下鼠标移动时候是否菜单会出现异常现象的,当然这些都可以通过加一些代码来解决的,主要是鼠标移出菜单外,菜单不会消失的,可以在其它的对象截取onmouseover事件来隐藏菜单的!
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1