javascript實(shí)現(xiàn)樹形菜單的方法
本文實(shí)例講述了javascript實(shí)現(xiàn)樹形菜單的方法。分享給大家供大家參考。具體如下:
var ME={ ini:{i:true,d:{},d1:{},h:0,h1:0,h2:0}, html:function(da,f){ var s='<ul'+(f?' class="f"':'')+'>'; for(var i=0,l=da.length;i<l;i++){ if(typeof(da[i].pid)=='object'){ s+='<li><button type="button" class="'+(i==0&&this.ini.i?'s1':(i+1==l?'s5':'s3'))+'" onclick="ME.yc(this)"></button><span><button type="button" class="r1"></button><a href="javascript:;">'+da[i].ming+'</a></span>'; this.ini.i=false; s+=this.html(da[i].pid,(i+1==l)); }else{ s+='<li><button type="button" class="'+(i+1==l?'e3':'e1')+'"></button><span><button type="button" class="m1"></button><a href="http://www.dbjr.com.cn" target="mainFrame">'+da[i].ming+'</a></span>'; } s+='</li>'; } s+='</ul>'; return s; }, st:function(id,da){ document.getElementById(id).innerHTML=this.html(da); }, yc:function(a){ var s=a.className.substr(1); if(s%2){ this.ini.d=a.parentNode.children[2]; this.ini.h1=this.hei(this.ini.d); this.ini.h3=this.ini.h1/10; this.yc1(1); a.className='s'+(parseInt(s)+1); a.parentNode.children[1].children[0].className='r2'; var ol=a.parentNode.parentNode._; if(typeof(ol)=='object'){ this.ini.d1=ol; this.ini.h=ol.offsetHeight; this.ini.h2=this.ini.h/10; this.yc2(1); ol.parentNode.children[0].className='s'+(parseInt(ol.parentNode.children[0].className.substr(1))-1); ol.parentNode.children[1].children[0].className='r1'; } a.parentNode.parentNode._=a.parentNode.children[2]; }else{ this.ini.d1=a.parentNode.children[2]; this.ini.h=this.ini.d1.offsetHeight; this.ini.h2=this.ini.h/10; this.yc2(1); a.className='s'+(parseInt(s)-1); a.parentNode.children[1].children[0].className='r1'; a.parentNode.parentNode._=''; } }, yc1:function(b){ var h1=ME.ini.h1-(11/(b+1)-1)*ME.ini.h3; with(ME.ini.d.style){ height=h1+'px'; display='block'; } if(b<10){ setTimeout('ME.yc1('+(b+1)+')',25); }else{ ME.ini.d.style.display='block'; ME.ini.d.style.height=''; } }, yc2:function(b){ var h1=(11/(b+1)-1)*ME.ini.h2; with(ME.ini.d1.style){ height=h1+'px'; } if(b<10){ setTimeout('ME.yc2('+(b+1)+')',25); }else{ ME.ini.d1.style.display=''; ME.ini.d1.style.height=''; } }, hei:function(a){ var b=a.cloneNode(true); b.style.position='absolute'; b.style.display='block'; b.style.visibility='hidden'; a.parentNode.appendChild(b); var h=b.offsetHeight; a.parentNode.removeChild(b); return h; } }
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
JavaScript通過attachEvent和detachEvent方法處理帶參數(shù)的函數(shù)
通過 attachEvent 和 detachEvent 方法處理帶參數(shù)的函數(shù)(示例代碼)2010-03-03JavaScript使ifram跨域相互訪問及與PHP通信的實(shí)例
這篇文章主要介紹了JavaScript使ifram跨域相互訪問及與PHP通信的實(shí)例,同時(shí)對(duì)同域間的訪問也作了詳細(xì)的演示,需要的朋友可以參考下2016-03-03基于Bootstrap使用jQuery實(shí)現(xiàn)簡單可編輯表格
這篇文章主要介紹了基于Bootstrap使用jQuery實(shí)現(xiàn)簡單可編輯表格的相關(guān)資料,需要的朋友可以參考下2016-05-05JavaScript跳出循環(huán)的幾種常用方法總結(jié)
這篇文章主要給大家介紹了關(guān)于JavaScript跳出循環(huán)的幾種常用方法,continue跳過當(dāng)前迭代,break終止循環(huán),label+break跳出多層循環(huán),return退出函數(shù),文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-06-06javascript 循環(huán)語句 while、do-while、for-in、for用法區(qū)別
本文章介紹了在學(xué)習(xí)javascript中的循環(huán)語句的用法,包while、do-while、for-in、for它們之間的區(qū)別,也是常用的循環(huán)語句了,有需要的朋友可以了解一下2012-03-03JS限制input框只能輸入0~100的正整數(shù)的兩種方法
本文給大家分享兩種方法實(shí)現(xiàn)JS限制input框只能輸入0~100的正整數(shù),方法二是直接通過設(shè)置三個(gè)屬性,type、min、max即可,就可以設(shè)置0~100的整數(shù),感興趣的朋友跟隨小編一起看看吧2024-02-02Three.js物理引擎Cannon.js創(chuàng)建簡單應(yīng)用程序
這篇文章主要為大家介紹了Three.js物理引擎Cannon.js創(chuàng)建簡單應(yīng)用程序詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04