JS技术

编写菜单横二级润滑 竖二级折叠菜单_源码_Javascript教程

字号+ 作者:H5之家 来源:H5之家 2015-10-01 09:01 我要评论( )

编写菜单横二级润滑 竖二级折叠菜单_源码,学习编写菜单横二级润滑 竖二级折叠菜单_源码,编写菜单横二级润滑 竖二级折叠菜单_源码,查看编写菜单横二级润滑 竖二级

教程网3月27日整理

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>横二级润滑 竖二级折叠菜单 01</title>
<style type="text/css">
<!--
body,ul,ol,li,dl,dt,dd,h1{ margin:0; padding:0; list-style:none;}
body { font:12px "Arial","宋体";color:#333;background:#FFF;}
a{border:none; text-decoration:none;}
#menu { width:980px; margin:30px auto;}
 #menu dl { padding-left:10px; height:30px;overflow:hidden; }
 #menu dl dd { float:left; padding-right:5px;}
 #menu dl dd a {display:block; padding-left:10px; background:url("") no-repeat 0 -60px;}
 #menu dl dd a span {
  display:block;
  color:#630;
  height:30px;
  width:50px;
  text-align:center;
  padding-right:10px;
  line-height:34px;
  font-size:14px;
  background:url("") no-repeat right -60px;
  overflow:hidden;
 }
 #menu dl dd a:hover,
 #menu dl dd.ok a { background-position: 0 -90px;}
 #menu dl dd a:hover span,
 #menu dl dd.ok a span { cursor:pointer; font-weight:bold; color:#FFF;background-position: right -90px;}
 #menu ol {clear:both; height:30px; background:url("") repeat-x 0 0;}
 #menu ol li { float:left;}
 #menu ol li a { color:#FFF; display:block; width:70px; text-align:center; height:30px; line-height:32px; overflow:hidden;}
 #menu ol li a:hover,
 #menu ol li.ok a{ font-weight:bold; background:url("") no-repeat 0 -30px;}
 
 #menu ol li span { width:150px;position:absolute;}
 #menu ol li span h1 {font:12px "宋体"; float:none; display:block; background:#E6E6E6;}
 #menu ol li span h1 a,
 #menu ol li.ok span h1 a,
 #menu ol li.ok span ul a{
  color:#333;
  width:148px;
  text-indent:10px;
  height:24px;
  line-height:26px;
  text-align:left;
  font-weight:normal;
  border-top:#FFF 1px solid;
  border-bottom:#A0A0A0 1px solid;
  border-right:#A0A0A0 1px solid;
  background-image:none;
 }
 #menu ol li span h1 a:hover,
 #menu ol li span h1.ok a {color:#930; font-weight:bold; background:#D9D9D9;}
 #menu ol li.ok span ul {width:147px; border:#E6E6E6 1px solid; border-top:none; overflow:hidden;}
 #menu ol li.ok span ul a {border:none;}
 #menu ol li.ok span ul a:hover { color:#930; font-weight:bold; text-indent:15px; background-image:none;}
.no { display:none;}
-->
</style>
<script language="javascript">
<!--//
function ShowMenu(obj,n){
 var dd = obj.parentNode.getElementsByTagName("dd");
 for(var i=0;i<dd.length;i++){dd[i].className = "";}
 dd[n].className = "ok";
 var ol = document.getElementById("menu").getElementsByTagName("ol");
 for(var i=0;i<ol.length;i++){ol[i].className = "no";}
 ol[n].className = "";
}
function ShowSpan(obj,n){
 var span = obj.parentNode.getElementsByTagName("span");
 for(var i=0;i<span.length;i++){span[i].className = "no";}
 span[n].className = "";
 var li = obj.parentNode.getElementsByTagName("li")
 for(var i=0;i<li.length;i++){li[i].className = "";}
 li[n].className = "ok";
}
function ShowUl(obj,n){
 var ul = obj.parentNode.getElementsByTagName("ul");
 var h1 = obj.parentNode.getElementsByTagName("h1");
 for(var i=0; i<h1.length;i++){
  h1[i].innerHTML = h1[i].innerHTML.replace("-","+");
  h1[i].className = "";
 }
 if(ul[n].className == "no"){
  ul[n].className = "";
  obj.className = "ok";
  obj.innerHTML = obj.innerHTML.replace("+","-");
 }else{
  ul[n].className = "no";
  return;
 }
 for(var i=0; i<ul.length;i++){if(i!=n){ ul[i].className = "no";}}
}
//-->
</script>
</head>
<body>
<div id="menu">
 <dl>
  <dd class="ok" onmouseover="javascript:ShowMenu(this,0);"><a href="javascript:void(0);"><span>菜单A</span></a></dd>
  <dd onmouseover="javascript:ShowMenu(this,1);"><a href="javascript:void(0);"><span>菜单B</span></a></dd>
  <dd onmouseover="javascript:ShowMenu(this,2);"><a href="javascript:void(0);"><span>菜单C</span></a></dd>
 </dl>
 
 <ol>
  <li onmouseover="javascript:ShowSpan(this,0);"><a href="javascript:void(0);">菜单A_0</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_0_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_0_0_0</a>
     <a href="javascript:void(0);">菜单A_0_0_1</a>
     <a href="javascript:void(0);">菜单A_0_0_2</a>
     <a href="javascript:void(0);">菜单A_0_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_0_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_0_1_0</a>
     <a href="javascript:void(0);">菜单A_0_1_1</a>
     <a href="javascript:void(0);">菜单A_0_1_2</a>
     <a href="javascript:void(0);">菜单A_0_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,1);"><a href="javascript:void(0);">菜单A_1</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_1_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_1_0_0</a>
     <a href="javascript:void(0);">菜单A_1_0_1</a>
     <a href="javascript:void(0);">菜单A_1_0_2</a>
     <a href="javascript:void(0);">菜单A_1_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_1_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_1_1_0</a>
     <a href="javascript:void(0);">菜单A_1_1_1</a>
     <a href="javascript:void(0);">菜单A_1_1_2</a>
     <a href="javascript:void(0);">菜单A_1_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,2);"><a href="javascript:void(0);">菜单A_2</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_2_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_2_0_0</a>
     <a href="javascript:void(0);">菜单A_2_0_1</a>
     <a href="javascript:void(0);">菜单A_2_0_2</a>
     <a href="javascript:void(0);">菜单A_2_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_2_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_2_1_0</a>
     <a href="javascript:void(0);">菜单A_2_1_1</a>
     <a href="javascript:void(0);">菜单A_2_1_2</a>
     <a href="javascript:void(0);">菜单A_2_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,3);"><a href="javascript:void(0);">菜单A_3</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_3_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_3_0_0</a>
     <a href="javascript:void(0);">菜单A_3_0_1</a>
     <a href="javascript:void(0);">菜单A_3_0_2</a>
     <a href="javascript:void(0);">菜单A_3_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_3_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_3_1_0</a>
     <a href="javascript:void(0);">菜单A_3_1_1</a>
     <a href="javascript:void(0);">菜单A_3_1_2</a>
     <a href="javascript:void(0);">菜单A_3_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,4);"><a href="javascript:void(0);">菜单A_4</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_4_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_4_0_0</a>
     <a href="javascript:void(0);">菜单A_4_0_1</a>
     <a href="javascript:void(0);">菜单A_4_0_2</a>
     <a href="javascript:void(0);">菜单A_4_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_4_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_4_1_0</a>
     <a href="javascript:void(0);">菜单A_4_1_1</a>
     <a href="javascript:void(0);">菜单A_4_1_2</a>
     <a href="javascript:void(0);">菜单A_4_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,5);"><a href="javascript:void(0);">菜单A_5</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_5_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_5_0_0</a>
     <a href="javascript:void(0);">菜单A_5_0_1</a>
     <a href="javascript:void(0);">菜单A_5_0_2</a>
     <a href="javascript:void(0);">菜单A_5_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_5_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_5_1_0</a>
     <a href="javascript:void(0);">菜单A_5_1_1</a>
     <a href="javascript:void(0);">菜单A_5_1_2</a>
     <a href="javascript:void(0);">菜单A_5_1_3</a>
    </ul>
   </span>
  </li>
 </ol>
 
 <!-- ol 0 End -->
 
 <ol class="no">
  <li onmouseover="javascript:ShowSpan(this,0);"><a href="javascript:void(0);">菜单B_0</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_0_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_0_0_0</a>
     <a href="javascript:void(0);">菜单B_0_0_1</a>
     <a href="javascript:void(0);">菜单B_0_0_2</a>
     <a href="javascript:void(0);">菜单B_0_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_0_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_0_1_0</a>
     <a href="javascript:void(0);">菜单B_0_1_1</a>
     <a href="javascript:void(0);">菜单B_0_1_2</a>
     <a href="javascript:void(0);">菜单B_0_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,1);"><a href="javascript:void(0);">菜单B_1</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_1_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_1_0_0</a>
     <a href="javascript:void(0);">菜单B_1_0_1</a>
     <a href="javascript:void(0);">菜单B_1_0_2</a>
     <a href="javascript:void(0);">菜单B_1_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_1_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_1_1_0</a>
     <a href="javascript:void(0);">菜单B_1_1_1</a>
     <a href="javascript:void(0);">菜单B_1_1_2</a>
     <a href="javascript:void(0);">菜单B_1_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,2);"><a href="javascript:void(0);">菜单B_2</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_2_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_2_0_0</a>
     <a href="javascript:void(0);">菜单B_2_0_1</a>
     <a href="javascript:void(0);">菜单B_2_0_2</a>
     <a href="javascript:void(0);">菜单B_2_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_2_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_2_1_0</a>
     <a href="javascript:void(0);">菜单B_2_1_1</a>
     <a href="javascript:void(0);">菜单B_2_1_2</a>
     <a href="javascript:void(0);">菜单B_2_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,3);"><a href="javascript:void(0);">菜单B_3</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_3_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_3_0_0</a>
     <a href="javascript:void(0);">菜单B_3_0_1</a>
     <a href="javascript:void(0);">菜单B_3_0_2</a>
     <a href="javascript:void(0);">菜单B_3_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_3_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_3_1_0</a>
     <a href="javascript:void(0);">菜单B_3_1_1</a>
     <a href="javascript:void(0);">菜单B_3_1_2</a>
     <a href="javascript:void(0);">菜单B_3_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,4);"><a href="javascript:void(0);">菜单B_4</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_4_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_4_0_0</a>
     <a href="javascript:void(0);">菜单B_4_0_1</a>
     <a href="javascript:void(0);">菜单B_4_0_2</a>
     <a href="javascript:void(0);">菜单B_4_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_4_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_4_1_0</a>
     <a href="javascript:void(0);">菜单B_4_1_1</a>
     <a href="javascript:void(0);">菜单B_4_1_2</a>
     <a href="javascript:void(0);">菜单B_4_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,5);"><a href="javascript:void(0);">菜单B_5</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单B_5_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单B_5_0_0</a>
     <a href="javascript:void(0);">菜单B_5_0_1</a>
     <a href="javascript:void(0);">菜单B_5_0_2</a>
     <a href="javascript:void(0);">菜单B_5_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单B_5_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单B_5_1_0</a>
     <a href="javascript:void(0);">菜单B_5_1_1</a>
     <a href="javascript:void(0);">菜单B_5_1_2</a>
     <a href="javascript:void(0);">菜单B_5_1_3</a>
    </ul>
   </span>
  </li>
 </ol>
 
 <!-- ol 1 End -->
 
 <ol class="no">
  <li onmouseover="javascript:ShowSpan(this,0);"><a href="javascript:void(0);">菜单C_0</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单C_0_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单C_0_0_0</a>
     <a href="javascript:void(0);">菜单C_0_0_1</a>
     <a href="javascript:void(0);">菜单C_0_0_2</a>
     <a href="javascript:void(0);">菜单C_0_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单C_0_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单C_0_1_0</a>
     <a href="javascript:void(0);">菜单C_0_1_1</a>
     <a href="javascript:void(0);">菜单C_0_1_2</a>
     <a href="javascript:void(0);">菜单C_0_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,1);"><a href="javascript:void(0);">菜单C_1</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单C_1_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单C_1_0_0</a>
     <a href="javascript:void(0);">菜单C_1_0_1</a>
     <a href="javascript:void(0);">菜单C_1_0_2</a>
     <a href="javascript:void(0);">菜单C_1_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单C_1_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单C_1_1_0</a>
     <a href="javascript:void(0);">菜单C_1_1_1</a>
     <a href="javascript:void(0);">菜单C_1_1_2</a>
     <a href="javascript:void(0);">菜单C_1_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,2);"><a href="javascript:void(0);">菜单C_2</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单C_2_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单C_2_0_0</a>
     <a href="javascript:void(0);">菜单C_2_0_1</a>
     <a href="javascript:void(0);">菜单C_2_0_2</a>
     <a href="javascript:void(0);">菜单C_2_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单C_2_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单C_2_1_0</a>
     <a href="javascript:void(0);">菜单C_2_1_1</a>
     <a href="javascript:void(0);">菜单C_2_1_2</a>
     <a href="javascript:void(0);">菜单C_2_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,3);"><a href="javascript:void(0);">菜单C_3</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单C_3_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单C_3_0_0</a>
     <a href="javascript:void(0);">菜单C_3_0_1</a>
     <a href="javascript:void(0);">菜单C_3_0_2</a>
     <a href="javascript:void(0);">菜单C_3_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单C_3_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单C_3_1_0</a>
     <a href="javascript:void(0);">菜单C_3_1_1</a>
     <a href="javascript:void(0);">菜单C_3_1_2</a>
     <a href="javascript:void(0);">菜单C_3_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,4);"><a href="javascript:void(0);">菜单C_4</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单C_4_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单C_4_0_0</a>
     <a href="javascript:void(0);">菜单C_4_0_1</a>
     <a href="javascript:void(0);">菜单C_4_0_2</a>
     <a href="javascript:void(0);">菜单C_4_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单C_4_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单C_4_1_0</a>
     <a href="javascript:void(0);">菜单C_4_1_1</a>
     <a href="javascript:void(0);">菜单C_4_1_2</a>
     <a href="javascript:void(0);">菜单C_4_1_3</a>
    </ul>
   </span>
  </li>
  <li onmouseover="javascript:ShowSpan(this,5);"><a href="javascript:void(0);">菜单A_5</a>
   <span class="no">
    <h1 onclick="javascript:ShowUl(this,0)"><a href="javascript:void(0);"> - 菜单A_5_0</a></h1>
    <ul>
     <a href="javascript:void(0);">菜单A_5_0_0</a>
     <a href="javascript:void(0);">菜单A_5_0_1</a>
     <a href="javascript:void(0);">菜单A_5_0_2</a>
     <a href="javascript:void(0);">菜单A_5_0_3</a>
    </ul>
    <h1 onclick="javascript:ShowUl(this,1)"><a href="javascript:void(0);"> + 菜单A_5_1</a></h1>
    <ul class="no">
     <a href="javascript:void(0);">菜单A_5_1_0</a>
     <a href="javascript:void(0);">菜单A_5_1_1</a>
     <a href="javascript:void(0);">菜单A_5_1_2</a>
     <a href="javascript:void(0);">菜单A_5_1_3</a>
    </ul>
   </span>
  </li>
 </ol>
</div>
</body>
</html>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评