JS实现无限级网页折叠菜单(类似树形菜单)

<html>
<head>
<title>无限级折叠菜单JS版</title>
<style>
<!--
body,ul,h3 {margin:0px; padding:0px;}
li {list-style-type:none;}
body{
 font-size:12px;
 color:#333;
 font-family: Simsun;
 line-height:15px;
 }
a{text-decoration:none;color:#004285;border:none;}
a:hover{text-decoration:none;color:#C33;}
#menu {
 width:260px;
 margin:50px auto;
 padding:10px;
 border:#EEE 1px solid;
 }
 #menu h3 {
 font-size:12px;
 }
 #menu ul {
 background:url("images/ul-bg.gif") repeat-y 5px 0px; overflow:hidden;
 }
 #menu ul li {
 padding:5px 0 2px 15px;
 background:url("images/tree-ul-li.gif") no-repeat 5px -32px;
 }
 #menu ul li ul {display:none;}
 #menu ul li em {
 cursor:pointer;
 display:inline-block;
 width:15px;
 float:left;
 height:15px;
 margin-left:-14px;
 background:url("images/tree-ul-li.gif") no-repeat -32px 2px;
 }
 #menu ul li em.off {
 background-position: -17px -18px;
 }
 #menu ul li#end {
 background-color:#FFF;
 }
 #menu ul.off {
 display:block;
 }
-->
</style>
</head>
<body>
<div id="menu">
 <h3>无限级折叠菜单JavaScript版</h3>
 <ul>
 <li><em></em><a href=‘javascript:void(0);‘>菜单_1_1</a>
 <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_2_1</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_2_2</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
 </ul>
 </li>
 <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_1_2</a>
 <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_2_1</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_2_2</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
 </ul>
 </li>
 </ul>
</div>
<script type="text/javascript">
(function(e){
 for(var _obj=document.getElementById(e.id).getElementsByTagName(e.tag),i=-1,em;em=_obj[++i];){
 em.onclick = function(){ //onmouseover
  var ul = this.nextSibling;
  if(!ul){return false;}
  ul = ul.nextSibling; if(!ul){return false;}
  if(e.tag != ‘a‘){ ul = ul.nextSibling; if(!ul){return false;} } //a 标签控制 隐藏或删除该行
  for(var _li=this.parentNode.parentNode.childNodes,n=-1,li;li=_li[++n];){
  if(li.tagName=="LI"){
   for(var _ul=li.childNodes,t=-1,$ul;$ul=_ul[++t];){
   switch($ul.tagName){
   case "UL":
    $ul.className = $ul!=ul?"" : ul.className?"":"off";
   break;
   case "EM":
    $ul.className = $ul!=this?"" : this.className?"":"off";
   break;
   }
   }
  }
  }
 }
 }
})({id:‘menu‘,tag:‘em‘});
</script>
</body>
</html>
时间: 2024-10-24 23:01:51

JS实现无限级网页折叠菜单(类似树形菜单)的相关文章

jquery树形菜单

转自:http://keleyi.com/dev/3068696139522ae4.htm 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"&g

EasyUI创建异步树形菜单和动态添加tab页面

创建异步树形菜单 添加树形菜单的ul标签 <ul class="easyui-tree" id="treeMenu"> </ul> 写js代码,对菜单的ul标签元素使用tree函数 $('#treeMenu').tree({ url:'tree_data.json' //url的值是异步获取数据的页面地址 }); 写用来异步获取数据的页面(tree_data.json页面).返回的需是Json值(此处用数组代替从数据库获取的数据,以省略连接数

利用多叉树实现Ext JS中的无限级树形菜单(一种构建多级有序树形结构JSON的方法)

一.问题研究的背景和意义 目前在Web应用程序开发领域,Ext JS框架已经逐渐被广泛使用,它是富客户端开发中出类拔萃的框架之一.在Ext的UI控件中,树形控件无疑是最为常用的控件之一,它用来实现树形结构的菜单.TreeNode用来实现静态的树形菜单,AsyncTreeNode用来实现动态的异步加载树形菜单,后者最为常用,它通过接收服务器端返回来的JSON格式的数据,动态生成树形菜单节点.动态生成树有两种思路:一种是一次性生成全部树节点,另一种是逐级加载树节点(利用AJAX,每次点击节点时查询下

jquery,tree无限级树形菜单+简单实用案例

jquery,tree无限级树形菜单+简单实用案例 我在项目中用到产品类别的树形.各种地方都要用. 我就封装起来,方便以后调用. 记录下来,希望给新手们提供帮助.要记得导入jquery.js  tree.js 哦 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri=&quo

JQUERY实现的小巧简洁的无限级树形菜单

JQUERY实现的小巧简洁的无限级树形菜单,可用于后台或前台侧栏菜单!兼容性也比较好. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <

JS树形菜单

超全的JS树形菜单源代码共享(有实例图) 树形菜单是很常用的效果,常用在管理软件当中,但是一套树形菜单已经不能满足需求,所以如果能有一套比较全面的树形菜单JS特效代码,将会非常方便,下面懒人萱将超全的JS树形菜单共享出来,相信你一定用得上. 一共包括八种,下面就一一介绍: 1.不同表现方式的JS树形菜单(如图所示) 2.复选框式的JS树形菜单(如图所示)左图为只可以选择单节点,右图为在选择子节点的同时选择父节点 3.可以重新排列节点并且具有拖放功能的js树形菜单(如图所示) 4.带有提示框的js

java--css+js做的树形菜单(完整版)

jsp页面: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":"

js实现无限级树形导航列表

<html><head><title>js实现的无限级树形下拉导航列表 </title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">     *{ margin:0; padding:0;    list-style:none;}    

实用的树形菜单控件tree

 jQuery plugin: Treeview 这个插件能够把无序列表转换成可展开与收缩的Tree. jQuery plugin: Treeview  jQuery  jstree jsTree是一个基于jQuery的Tree控件.支持XML,JSON,Html三种数据源.提供创建,重命名,移动,删除,拖\放节点操作.可以自己自定义创建,删除,嵌套,重命名,选择节点的规则.在这些操作上可以添加多种监听事件.  jstree  jQuery UI Widgets  FileTreePanel F