本文实例讲述了javascript实现树形菜单的方法。分享给大家供大家参考。具体如下:
var ME={ ini:{i:true,d:{},d1:{},h:0,h1:0,h2:0}, html:function(da,f){ var s='<ul'+(f"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" 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"></button><span><button type="button" class="m1"></button><a href="https://www.jb51.net" 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; } }
希望本文所述对大家的javascript程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】