忘了是从哪里找来的,生命一下,不是原创,可以生成树,另外,www.9949.net,能找到各种菜单。
<html>
<head></head>
<script language="javascript">
var strStyle='<style type="text/css">'
strStyle+='span.SelectIng{color:#ff00ff;border:solid 1pt #666666;padding:0.5pt;height:4px;background-color:#cccccc;}'
strStyle+='span.NoSelect{color:#000084;border:solid 1pt #ffffff;padding:0.5pt;height:4px;background-color:#ffffff;}'
strStyle+='span.SelectEd{color:#D02090;border:solid 1pt #888888;padding:0.5pt;height:4px;background-color:#f3f3f3;}'
strStyle+='</style>'
document.write(strStyle)
var myRs=new Array(), selectItem;
function InsertItem(s){myRs[myRs.length++] = s.split(/,/);} function compare(a,b) {return parseInt(a[1]) - parseInt(b[1])} function ExCloAll(n){
var d=document.all('0'), e=d.all.tags('div')
for (i=0;i<e.length;i++)e[i].style.display=(n==1?'block':'none')
e=d.all.tags('p')
for (i=0;i<e.length;i++){if(ChkExist(e[i].children[1].value))e[i].children[0].innerText=(n==1?'- ':'+ ')}
} function ExCloItem(){
var c,e=event.srcElement, p=e.parentElement.children
if(selectItem!=null)selectItem.className='NoSelect';
e.className='SelectEd'
selectItem=event.srcElement;
if(c=document.all(e.value)){
p[0].innerText=(p[0].innerText=='+ '?'- ':'+ ')
c.style.display=(c.style.display=='none'?'block':'none')
}else{p[0].innerText='- '}
} function ExCloItem2(){
var c,e=event.srcElement, p=e.parentElement.children
if(c=document.all(p[1].value)){
e.innerText=(e.innerText=='+ '?'- ':'+ ')
c.style.display=(c.style.display=='block'?'none':'block')
}else e.innerText='- '
}
function OutItem(){
var e=event.srcElement
if(selectItem != '')e.className=(selectItem==e?'SelectEd':'NoSelect')
else e.className='NoSelect'
}
function ChkExist(n)
{
n=parseInt(n)
if((n<myRs[0][1]) || (n>myRs[myRs.length-1][1]))return false
var a,b,c,x=0, y=parseInt(myRs.length/2), z=myRs.length-1
while((x!=y)&&(y!=z))
{
a=myRs[x][1], b=myRs[y][1], c=myRs[z][1]
if(n==a ||n==b ||n==c)return true
if(n>b)
x=y;
else z=y;y=parseInt(x+z);
y=parseInt((x+z)/2);
}
return false
}
function drawTree(n)
{
if(n==0)
{
myRs.sort(compare)
document.write('<p style="font:10pt;cursor:hand;"><span onclick="ExCloAll(1)">全部展開</span> <span onclick="ExCloAll(0)">全部合攏</span></p>')
}
if (ChkExist(n)!=true) return
document.write('<div id="'+n+'" style="font:10pt;cursor:hand;'+(n!=0?'position:relative;left:20;display:none;':'')+'">')
for(var i=0;i<myRs.length;i++)
{
if (parseInt(myRs[i][1])>n) break; //如果不是需要显示的当前级菜单
if (myRs[i][1]==n)
{
document.write('<p style="margin:0pt;"><span style="vertical-align:top;" onclick="ExCloItem2()">'+(ChkExist(myRs[i][0])?'+ ':'- ')+'</span>')
document.write('<span onclick="ExCloItem()" value="'+myRs[i][0]+'" class="NoSelect" onmouseout="OutItem()" onmouseover="this.className=\'SelectIng\'">'+myRs[i][2]+'</span></p>')
drawTree(myRs[i][0])
}
}
document.write('</div>')
}
</script>
<body><script language="javascript">
InsertItem('1,0,根目錄1')
InsertItem('11,1,子目錄1')
InsertItem('111,11,孫目錄1')
InsertItem('1111,111,曾孫目錄')
InsertItem('11111,1111,玄孫目錄')
InsertItem('12,1,子目錄2')
InsertItem('2,0,根目錄2')
InsertItem('21,2,子目錄A')
InsertItem('22,2,子目錄B')
InsertItem('3,0,根目錄3')
drawTree(0)
</script>
</body>
</html>
<html>
<head></head>
<script language="javascript">
var strStyle='<style type="text/css">'
strStyle+='span.SelectIng{color:#ff00ff;border:solid 1pt #666666;padding:0.5pt;height:4px;background-color:#cccccc;}'
strStyle+='span.NoSelect{color:#000084;border:solid 1pt #ffffff;padding:0.5pt;height:4px;background-color:#ffffff;}'
strStyle+='span.SelectEd{color:#D02090;border:solid 1pt #888888;padding:0.5pt;height:4px;background-color:#f3f3f3;}'
strStyle+='</style>'
document.write(strStyle)
var myRs=new Array(), selectItem;
function InsertItem(s){myRs[myRs.length++] = s.split(/,/);} function compare(a,b) {return parseInt(a[1]) - parseInt(b[1])} function ExCloAll(n){
var d=document.all('0'), e=d.all.tags('div')
for (i=0;i<e.length;i++)e[i].style.display=(n==1?'block':'none')
e=d.all.tags('p')
for (i=0;i<e.length;i++){if(ChkExist(e[i].children[1].value))e[i].children[0].innerText=(n==1?'- ':'+ ')}
} function ExCloItem(){
var c,e=event.srcElement, p=e.parentElement.children
if(selectItem!=null)selectItem.className='NoSelect';
e.className='SelectEd'
selectItem=event.srcElement;
if(c=document.all(e.value)){
p[0].innerText=(p[0].innerText=='+ '?'- ':'+ ')
c.style.display=(c.style.display=='none'?'block':'none')
}else{p[0].innerText='- '}
} function ExCloItem2(){
var c,e=event.srcElement, p=e.parentElement.children
if(c=document.all(p[1].value)){
e.innerText=(e.innerText=='+ '?'- ':'+ ')
c.style.display=(c.style.display=='block'?'none':'block')
}else e.innerText='- '
}
function OutItem(){
var e=event.srcElement
if(selectItem != '')e.className=(selectItem==e?'SelectEd':'NoSelect')
else e.className='NoSelect'
}
function ChkExist(n)
{
n=parseInt(n)
if((n<myRs[0][1]) || (n>myRs[myRs.length-1][1]))return false
var a,b,c,x=0, y=parseInt(myRs.length/2), z=myRs.length-1
while((x!=y)&&(y!=z))
{
a=myRs[x][1], b=myRs[y][1], c=myRs[z][1]
if(n==a ||n==b ||n==c)return true
if(n>b)
x=y;
else z=y;y=parseInt(x+z);
y=parseInt((x+z)/2);
}
return false
}
function drawTree(n)
{
if(n==0)
{
myRs.sort(compare)
document.write('<p style="font:10pt;cursor:hand;"><span onclick="ExCloAll(1)">全部展開</span> <span onclick="ExCloAll(0)">全部合攏</span></p>')
}
if (ChkExist(n)!=true) return
document.write('<div id="'+n+'" style="font:10pt;cursor:hand;'+(n!=0?'position:relative;left:20;display:none;':'')+'">')
for(var i=0;i<myRs.length;i++)
{
if (parseInt(myRs[i][1])>n) break; //如果不是需要显示的当前级菜单
if (myRs[i][1]==n)
{
document.write('<p style="margin:0pt;"><span style="vertical-align:top;" onclick="ExCloItem2()">'+(ChkExist(myRs[i][0])?'+ ':'- ')+'</span>')
document.write('<span onclick="ExCloItem()" value="'+myRs[i][0]+'" class="NoSelect" onmouseout="OutItem()" onmouseover="this.className=\'SelectIng\'">'+myRs[i][2]+'</span></p>')
drawTree(myRs[i][0])
}
}
document.write('</div>')
}
</script>
<body><script language="javascript">
InsertItem('1,0,根目錄1')
InsertItem('11,1,子目錄1')
InsertItem('111,11,孫目錄1')
InsertItem('1111,111,曾孫目錄')
InsertItem('11111,1111,玄孫目錄')
InsertItem('12,1,子目錄2')
InsertItem('2,0,根目錄2')
InsertItem('21,2,子目錄A')
InsertItem('22,2,子目錄B')
InsertItem('3,0,根目錄3')
drawTree(0)
</script>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货