免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1153 | 回复: 0
打印 上一主题 下一主题

自己YY的js树形菜单 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:44 |只看该作者 |倒序浏览
  1. <style>
  2. .hide {

  3.     display:none;    
  4. }
  5. .show {
  6.     display:block;
  7. }
  8. </style>

  9. <script type="text/javascript">
  10.     
  11.     var EventUtil = {
  12.         
  13.         addHandler: function(element, type, handler){
  14.             if (element.addEventListener){
  15.                 element.addEventListener(type, handler, false);
  16.             }
  17.             else if (element.attachEvent) {
  18.                 element.attachEvent("on"+type, handler);
  19.             }
  20.             else {
  21.                 element["on"+type] = handler;    
  22.             }    
  23.         },
  24.         
  25.         removeHandler: function(element, type, handler){
  26.             if (element.removeEventListener){
  27.                 element.removeEventListener(type, handler, false);
  28.             }
  29.             else if (element.detachEvent){
  30.                 element.detachEvent("on"+type, handler);    
  31.             }
  32.             else {
  33.                 element["on"+type] = null;    
  34.             }
  35.         },
  36.         
  37.         getEvent: function(event) {
  38.             return event ? event : window.event;    
  39.         },
  40.         
  41.         getTarget: function(event) {
  42.             return event.target || event.srcElement;    
  43.         }
  44.             
  45.     }


  46.     function change(event) {
  47.         var event = event;
  48.         var element = this;
  49.         var odiv = EventUtil.getTarget(event).getElementsByTagName("div").item(0);
  50.         //alert(odiv.tagName);
  51.         var CName = element.className;
  52.         //var divCName = odiv.getElementByTagName("div").item(0).className;
  53.         //alert(divCName);
  54.         if(CName == "level_1"){
  55.             element.className = "level_2";
  56.             odiv.className = "show"
  57.         }
  58.         else
  59.         {
  60.             element.className = "level_1";
  61.             odiv.className = "hide";
  62.         }
  63.         
  64.     }
  65.     
  66.     window.onload=function(){
  67.     var ou=document.getElementById("content_left_colume").getElementsByTagName("ul") ;
  68.     
  69.     //alert(ou.length);
  70.     for (var i=0 ; i<ou.length ;i++){
  71.         //alert(ou.item(i).tagName);
  72.         EventUtil.addHandler(ou.item(i),"click",change);
  73.         }
  74.     }
  75.     
  76. </script>
  77. <div id="content_left_colume">

  78.     <ul class="level_1">
  79.         <li >11111
  80.             <div class="hide">
  81.                 <a href=#>222222222</a>
  82.                 <a href=#>222222222</a>
  83.                 <a href=#>222222222</a>
  84.                 <a href=#>222222222</a>
  85.                 <a href=#>222222222</a>
  86.                 <a href=#>222222222</a>
  87.                 <a href=#>222222222</a>
  88.              </div>
  89.         </li>
  90.     </ul>
  91.     <ul class="level_1">
  92.         <li >11111
  93.             <div class="hide">
  94.                 <a href=#>222222222</a>
  95.                 <a href=#>222222222</a>
  96.                 <a href=#>222222222</a>
  97.                 <a href=#>222222222</a>
  98.                 <a href=#>222222222</a>
  99.                 <a href=#>222222222</a>
  100.                 <a href=#>222222222</a>
  101.              </div>
  102.         </li>
  103.     </ul>
  104.     <ul class="level_1">
  105.         <li >11111
  106.             <div class="hide">
  107.                 <a href=#>222222222</a>
  108.                 <a href=#>222222222</a>
  109.                 <a href=#>222222222</a>
  110.                 <a href=#>222222222</a>
  111.                 <a href=#>222222222</a>
  112.                 <a href=#>222222222</a>
  113.                 <a href=#>222222222</a>
  114.              </div>
  115.         </li>
  116.     </ul>

  117. </div>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP