我做的一个n级前台菜单树,hiahia
1,绝对前台菜单。打开折叠都不需要刷新.....(废话)
2,树的输入结构是oa;oa-fd;oa-mama;oa-fd-11;oa-fd-12;在frmonload函数里面strCategory 把树结构字符串赋给它。 就得到需要的树了
3,使用方法:a 把以下代码拷到header里 b onload事件写 c frmOnload() 需要菜单的地方写上<div id=OK></div>
用不了的说一声
/** tree by IntoTheRain -----------------------------------*/
function lhTree(entry, showHint, open){
this.branches = new Array();
this.open = open;
this.showHint = showHint;
this.entry = entry;
this.write = writeTree;
this.addBranch = addBranch;
this.id= showHint;
}
function addBranch(branch){
this.branches[this.branches.length] = branch;
}
function writeTree()
{
var sHTML = '';
var showImg;
if (this.open == true)
{
showImg = 'openfolder.gif';
}
else if(this.branches.length>0){
showImg = 'closefolder.gif';
}else{
showImg = 'leaffolder.gif';
}
var tmpsplit = this.showHint.split('-');
if (showImg == 'leaffolder.gif')
{
sHTML += '<span><img src=' + showImg + ' border=0 >'
+ '<a href=' + this.entry + ' target=_blank>' + tmpsplit[tmpsplit.length-1] + '</a></span><br>'
} else
{
sHTML += '<span><img src=' + showImg + ' border=0 style="cursor: hand" onClick=openClick(this,"'+ this.showHint +'")>'
+ '<a href=' + this.entry + ' target=_blank>' + tmpsplit[tmpsplit.length-1] + '</a></span><br>'
}
var visibleT;
if(this.open)
{ visibleT='block';}
else { visibleT='none';}
sHTML += '<div style="margin-left:10px" id=' + this.showHint + ' style=display:' + visibleT + '>';
for(var i=0; i<this.branches.length ; i++)
{
sHTML += this.branches[i].write();
}
sHTML +='</div>'
return sHTML;
}
function openClick(objThis,unid)
{
if (objThis.src.indexOf('openfolder.gif')>-1)
{
objThis.src = 'closefolder.gif';
}else
{
objThis.src = 'openfolder.gif';
}
var objBranch = document.getElementById(unid).style;
if (objBranch.display=="block")
objBranch.display="none";
else
objBranch.display="block";;
// objBranch.open = !objBranch.open;
}
var strCategory;
var StackArray = new Array(10);
var entryTree;
function frmOnload()
{
strCategory = "oa;oa-fd;oa-mama;oa-fd-11;oa-fd-12;oa-fd-11-2;calls;inter;inter-whisper;inter-whyyes";
var ppArray = strCategory.split(';');
ppArray = ppArray.sort();
var top = 0;
entryTree = new lhTree('/oa/test.nsf/alltt?openform&category=&','',true);
StackArray[0] = entryTree;
var bOpen = true;
for(var i=0;i<ppArray.length;i++)
{
var added = new lhTree('/oa/test.nsf/alltt?openform&category=' + ppArray[i] + '&', ppArray[i], false);
StackArray[top].addBranch(added);
top ++;
StackArray[top] = added;
if (i==ppArray.length-1)
break;
for(j=top;j>-1;j--)
{
if(ppArray[i+1].indexOf(StackArray[top].showHint)==-1){
top--;
}else{
break;
}
}
}
document.all('OK').innerHTML = entryTree.write();
}