Javascript 动态目录树生成实例代码

发布时间:2020-11-21编辑:脚本学堂
本文分享一个javascript生成动态目录的实现代码,感兴趣的朋友参考下。

1,test_index.html
 

复制代码 代码示例:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Divides the pages vertically in three frames.">
<title>javascript动态目录树--www.jb200.com</title>
<script language="JavaScript">
var total_folder = 10;
var show_hide = new Array(total_folder);
show_hide[0]=1;
for(i=1;i<total_folder;i++)
{
  show_hide[i]=2;
}
</script>
</head>
<frameset cols=’1*,1*’>
  <frame name=’left’ scrolling=’auto’ marginwidth=’10’ marginheight=’14’ src="test_test.html">");
  <frame name=’right’ scrolling=’auto’ marginwidth=’10’ marginheight=’14’>");
<noframes>
</frameset>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
</body>
</html>

2,test_test.html
 

复制代码 代码示例:
<html>
<head>
<title>Javascript动态目录树--www.jb200.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" bgcolor="#ffffff" marginheight="0" link=blue vlink=blue alink=blue>
<script language="javascript" type="text/javascript">
var total_folder = 10;
var the_folder = new Array(total_folder);
the_folder[0] = ["share",0,2];
the_folder[1] = ["partition1",1,1];
the_folder[2] = ["folder1",2,2];
the_folder[3] = ["folder11",3,0];
the_folder[4] = ["folder12",3,1];
the_folder[5] = ["folder121",4,0];
the_folder[6] = ["partition2",1,2];
the_folder[7] = ["p1",2,0];
the_folder[8] = ["p2",2,1];
the_folder[9] = ["p21",3,0];
for(i=0;i<total_folder;i++)
{
  if((the_folder[i][2]==0)||(parent.show_hide[i]==1))
  {
    document.write("<div>");
    document.write("<img src=white.gif width="+25*the_folder[i][1]+" height=18>");
    document.write("<img src=5.1.gif width=18 height=18><a href=javascript:list_folder("+(i)+");><span>"+the_folder[i][0]);
    document.write("</span></a></div>");
  }
  else
  {
    document.write("<div>");
    document.write("<img src=white.gif width="+25*the_folder[i][1]+" height=18>");
    document.write("<img src=3.9.gif width=18 height=18><a href=javascript:list_folder("+(i)+");><span>"+the_folder[i][0]);
    document.write("</span></a></div>");
    if(parent.show_hide[i]==2)
    {
      i = check_hidden(i);
    }
  }
}
function check_hidden(x)
{
  var start_point = x;
  var check_no = start_point+1;
  if(check_no == total_folder)
  return check_no;
  while(the_folder[check_no][1]>the_folder[start_point][1])
  {
    check_no++;
    if(check_no == total_folder)
    return check_no;
  }
  start_point = check_no-1;
  return start_point;
}
function list_folder(x)
{
  if(parent.show_hide[x]==1)
  {
    parent.show_hide[x]=2;
  }
  else
  {
    parent.show_hide[x]=1;
  }
  location.href="test_test.html"
}
</script>
</body>
</html>