资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
JavaScript教程
>>>
JavaScript 双级下拉菜单实现代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript下拉菜单</title> <style type="text/css"> * { padding:0; margin:0; } body { font-family:verdana, sans-serif; font-size:small; } #navigation, #navigation li ul { list-style-type:none; } #navigation { margin:40px; }/*可有可无属性,是内容与边的距离*/ #navigation li { float:left; text-align:center; position:relative;/*position:relative一定要写,是下面的链接相对它绝对定位*/ } #navigation li a:link, #navigation li a:visited { display:block; text-decoration:none; color:#000; width:120px;/*改变所有的导航栏的长度*/ height:30px;/*改变所有导航栏的高度*/ line-height:30px; border:1px solid red;/*没有这个属性的所有的导航栏的颜色就连在一起了*/ background:#c5dbf2; padding-left:10px; } #navigation li ul { display:none; position:absolut; top:40px; left:0; margin-top:1px;/*可有可无,无的话主菜单和二级菜单就会没有空隙*/ width:120px; } #h{ position:absolute; top:74px; left: 40px; } </style> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20type%3D%22text%2Fjavascript%22%3E%20%0D%0Afunction%20displaySubMenu(li)%20%7B%20%0D%0Avar%20subMenu%20%3D%20li.getElementsByTagName(%22ul%22)%5B0%5D%3B%20%0D%0AsubMenu.style.display%20%3D%20%22block%22%3B%20%0D%0A%7D%20%0D%0Afunction%20hideSubMenu(li)%20%7B%20%0D%0Avar%20subMenu%20%3D%20li.getElementsByTagName(%22ul%22)%5B0%5D%3B%20%0D%0AsubMenu.style.display%20%3D%20%22none%22%3B%20%0D%0A%7D%20%0D%0A%3C%2Fscript%3E"> </head> <body> <div> <div > <ul id="navigation"> <li onmouseover="displaySubMenu(li1)" onmouseout="hideSubMenu(this)" id="li1"><a href="#" _ewebeditor_ta_href="%23">栏目1</a><!--函数里面用id和this都代表了这个节点的意思--> <ul> <li><a href="#" _ewebeditor_ta_href="%23">栏目2->菜单1</a></li> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单2</a></li> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单3</a></li> </ul> </li> <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"><a href="#" _ewebeditor_ta_href="%23">栏目1</a> <ul> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单1</a></li> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单2</a></li> </ul> </li> <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"><a href="#" _ewebeditor_ta_href="%23">栏目1</a> <ul> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单1</a></li> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单2</a></li> <li><a href="#" _ewebeditor_ta_href="%23">栏目1->菜单3</a></li> </ul> </li> </ul> </div> </div> </body> </html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程