>  기사  >  웹 프론트엔드  >  JS CSS_javascript 기술을 사용하여 TreeMenu 보조 트리 메뉴를 구현하는 전체 예

JS CSS_javascript 기술을 사용하여 TreeMenu 보조 트리 메뉴를 구현하는 전체 예

WBOY
WBOY원래의
2016-05-16 15:38:461550검색

이 기사의 예에서는 JS CSS를 사용하여 TreeMenu 보조 트리 메뉴를 구현하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 내용은 다음과 같습니다.

다음은 2단계 트리 메뉴의 예입니다. 매우 아름다운 트리 메뉴인 CSS TreeMenu는 웹사이트 오른쪽에 사용하기에 더 적합합니다.

런닝 효과 스크린샷은 다음과 같습니다.

온라인 데모 주소는 다음과 같습니다.

http://demo.jb51.net/js/2015/js-css-treemenu-2l-menu-codes/

구체적인 코드는 다음과 같습니다.

<!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" lang="gb2312">
<head>
<title>二级树形菜单示例:CSS TreeMenu</title>
<style type="text/css" media="all">
a,a:visited {color:#333;text-decoration:none;}
a:hover {color:#f60;}
body,td {font:13px "Geneva","宋体", "Arial", "Helvetica",sans-serif;}
ul,li {margin:0;padding:0;list-style:none;}
h1,h2,h3,h4,h5,h6 {margin:0;padding:0;}
h1 {padding:5px;color:#900;font:16px bold "Geneva","宋体", "Arial", "Helvetica",sans-serif;}
h1 small {font-size:11px;font-weight:normal;color:#660;}
.TreeWrap {width:200px;}
.MenuBox .titBox a,
.MenuBox .titBox a:visited,
.MenuBox2 .titBox a,
.MenuBox2 .titBox a:visited {margin-left:10px;padding-left:40px;color:#003;font-size:12px;display:block;}
.MenuBox .titBox h3 a {background:url(images/ico_folder_open.gif) no-repeat 0 40%;}
.MenuBox .titBox h3.Fst a {background:url(images/ico_folder_open_fst.gif) no-repeat 0 40%;}
.MenuBox .titBox h3.Lst a {background:url(images/ico_folder_open_lst.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3 a {background:url(images/ico_folder.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3.Fst a {background:url(images/ico_folder_fst.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3.Lst a {line-height:250%;background:url(images/icon_exit.gif) no-repeat 0 0;}
.MenuBox2 .txtBox {display:none;}
.MenuBox .txtBox ul li {padding-left:65px;line-height:150%;}
.MenuBox .txtBox .num {color:#e00;}
.MenuBox .txtBox ul {background:url(images/line_y.gif) repeat-y 16px 0;}
.MenuBox .txtBox ul li {background:url(images/t.gif) no-repeat 28px 50%;}
.MenuBox .txtBox ul li.Lst {background:url(images/t_lst.gif) no-repeat 28px 50%;}
</style>
<script type="text/javascript">
 <!--
 function ExChgClsName(Obj,NameA,NameB){
 var Obj=document.getElementById(Obj)&#63;document.getElementById(Obj):Obj;
 Obj.className=Obj.className==NameA&#63;NameB:NameA;
 }
 function showMenu(iNo){
 ExChgClsName("Menu_"+iNo,"MenuBox","MenuBox2");
 }
-->
</script>
</head>
<body>
<h1>CSS TreeMenu <small>By 枫岩@IECN.Net</small></h1>
<div class="TreeWrap">
<div class="MenuBox" id="Menu_0">
<div class="titBox"><h3 class="Fst"><a href="javascript:showMenu(0);">同事</a></h3></div>
<div class="txtBox">
 <ul>
 <li><a href="#">Dodo</a></li>
 <li><a href="#">小春</a></li>
 <li><a href="#">小林</a></li>
 <li><a href="#">小龙</a></li>
 <li class="Lst"><a href="#">枫岩</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_1">
<div class="titBox"><h3><a href="javascript:showMenu(1);">客户</a></h3></div>
<div class="txtBox">
 <ul>
 <li><a href="#">Dodo</a></li>
 <li><a href="#">小春</a></li>
 <li><a href="#">小林</a></li>
 <li><a href="#">小龙</a></li>
 <li class="Lst"><a href="#">枫岩</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_2">
<div class="titBox"><h3><a href="javascript:showMenu(2);">朋友</a></h3></div>
<div class="txtBox">
 <ul>
 <li><a href="#">Dodo</a></li>
 <li><a href="#">小春</a></li>
 <li><a href="#">小林</a></li>
 <li><a href="#">小龙</a></li>
 <li class="Lst"><a href="#">枫岩</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_3">
<div class="titBox"><h3><a href="javascript:showMenu(3);">家人</a></h3></div>
<div class="txtBox">
 <ul>
 <li><a href="#">Dodo</a></li>
 <li><a href="#">小春</a></li>
 <li><a href="#">小林</a></li>
 <li><a href="#">小龙</a></li>
 <li class="Lst"><a href="#">枫岩</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2">
<div class="titBox"><h3 class="Lst"><a href="#">退出系统</a></h3></div>
</div><!--MenuBox-->
</div>
</body>
</html>

이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.