The example in this article describes the way JavaScript implements a tree menu. Share to everyone for your reference. as follows:
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= ' butt On "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.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;
}
}
The
wants this article to help you with your JavaScript programming.