打造网页中的树型菜单

简介: 打造网页中的树型菜单
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>TreeMenu</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<!--
2006-04-28 改进,使用制表符
2006-04-27 创建
//-->
<META NAME="Author" CONTENT="PurpleEndurer">
<META NAME="Keywords" CONTENT="网页制作,JavaScript,树型目录,树型菜单">
<META NAME="Description" CONTENT="网页制作,JavaScript,树型目录,树型菜单">
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var root = new Array();
root[0] = new Array("/index.htm*河池市农业信息网首页", "/scenery/list.htm?1*河池风光", "#*子目录2", "#*子目录3");
root[1] = new Array("#*主目录2", "#*子目录1", "#*子目录2", "#*子目录3");
var strPreURL ="​​ ​http://www.hcny.gov.cn​​​";
//-->
function expendDir(i)
{
 var dir  = eval("document.all.dir" + i);
 var plus = eval("document.all.plus" + i);
 dir.style.display = ("none"==dir.style.display) ? "" : "none";
 plus.innerText = ("none"==dir.style.display) ? "┼" : (0==i ? "┬" : "├");
}

function subdirstr(i)
{
 return "<b id=/"plus"+ i + "/" style=/"cursor: pointer;/" οnclick=/"expendDir("+ i + ");/">┼</b>&nbsp;"
}

function writeSubItem(i)
{
 var subitemlen = root[i].length;
 document.write("<div id=/"dir");
 document.write(i);
 document.write("/" style=/"display:none/">");

 subitemlen--;

 for (j = 1; j <= subitemlen; j++)
 {

  substr  = root[i][j].split('*');
  document.write(j == subitemlen ? "└─&nbsp;" : "├─&nbsp;");

  if ("#" == substr[0])
  {
   document.write();
   document.write(substr[1]);
  }
  else
  {
   document.write("<a href=/"");
   document.write(strPreURL);
   document.write(substr[0]);
   document.write("/">");
   document.write(substr[1]);
   document.write("</a>");
  }
  document.write("<BR>");
 } //for(j)
 document.write("</div>");
} //writeSubItem()

function showMenu()
{
 var i, j, RootLen = root.length;
 if (0==RootLen)
 {
  document.write("暂无菜单");
  return;
 }

 for (i = 0; i < RootLen; i++)
 {
  var subitemlen = root[i].length;
  var substr  = root[i][0].split('*');
  document.write(subitemlen>1 ? subdirstr(i) : '-');

  if ("#" == substr[0])
  {
   document.write(substr[1]);
  }
  else
  {
   document.write("<a href=/"");
   document.write(strPreURL);
   document.write(substr[0]);
   document.write("/" target=/"ifrmInfo/" class=/"TreeItemLink/">");
   document.write(substr[1]);
   document.write("</a>");
  } //if

  if (subitemlen > 1)
  {
   writeSubItem(i);
  }

  document.write("<BR>");
 } //for(i);
} //ShowMenu()

showMenu();
</SCRIPT>

</BODY>
</HTML>

 

使用图形版:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>TreeMenu</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<!--
2006-04-28 改进,使用制表符
2006-04-27 创建
//-->
<META NAME="Author" CONTENT="PurpleEndurer">
<META NAME="Keywords" CONTENT="网页制作,JavaScript,树型目录,树型菜单">
<META NAME="Description" CONTENT="网页制作,JavaScript,树型目录,树型菜单">
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var root = new Array();
root[0] = new Array("/index.htm*河池市农业信息网首页", "/scenery/list.htm?1*河池风光", "#*子目录2", "#*子目录3");
root[1] = new Array("#*主目录2", "#*子目录1", "#*子目录2", "#*子目录3");
var strPreURL ="​​ ​http://www.hcny.gov.cn​​​";
//-->
function expendDir(i)
{
 var dir  = eval("document.all.dir" + i);
 var plus = eval("document.all.plus" + i);
 dir.style.display = ("none"==dir.style.display) ? "" : "none";
 plus.innerText = ("none"==dir.style.display) ? "┼" : (0==i ? "┬" : "├");
}

function subdirstr(i)
{
 return "<b id=/"plus"+ i + "/" style=/"cursor: pointer;/" οnclick=/"expendDir("+ i + ");/">┼</b>&nbsp;"
}

function writeSubItem(i)
{
 var subitemlen = root[i].length;
 document.write("<div id=/"dir");
 document.write(i);
 document.write("/" style=/"display:none/">");

 subitemlen--;

 for (j = 1; j <= subitemlen; j++)
 {

  substr  = root[i][j].split('*');
  document.write(j == subitemlen ? "└─&nbsp;" : "├─&nbsp;");

  if ("#" == substr[0])
  {
   document.write();
   document.write(substr[1]);
  }
  else
  {
   document.write("<a href=/"");
   document.write(strPreURL);
   document.write(substr[0]);
   document.write("/">");
   document.write(substr[1]);
   document.write("</a>");
  }
  document.write("<BR>");
 } //for(j)
 document.write("</div>");
} //writeSubItem()

function showMenu()
{
 var i, j, RootLen = root.length;
 if (0==RootLen)
 {
  document.write("暂无菜单");
  return;
 }

 for (i = 0; i < RootLen; i++)
 {
  var subitemlen = root[i].length;
  var substr  = root[i][0].split('*');
  document.write(subitemlen>1 ? subdirstr(i) : '-');

  if ("#" == substr[0])
  {
   document.write(substr[1]);
  }
  else
  {
   document.write("<a href=/"");
   document.write(strPreURL);
   document.write(substr[0]);
   document.write("/" target=/"ifrmInfo/" class=/"TreeItemLink/">");
   document.write(substr[1]);
   document.write("</a>");
  } //if

  if (subitemlen > 1)
  {
   writeSubItem(i);
  }

  document.write("<BR>");
 } //for(i);
} //ShowMenu()

showMenu();
</SCRIPT>

</BODY>
</HTML>
相关文章
58EasyUI 树形菜单- 树形网格动态加载
58EasyUI 树形菜单- 树形网格动态加载
42 0
|
3月前
|
开发框架 前端开发 搜索推荐
在WInform开发中实现工具栏/菜单的动态呈现
在WInform开发中实现工具栏/菜单的动态呈现
|
6月前
publiccms实现多层级选项卡效果
publiccms实现多层级选项卡效果
|
6月前
|
前端开发 JavaScript
扁平化菜单功能制作
扁平化菜单功能制作
扁平化菜单功能制作
54EasyUI 树形菜单- 树形菜单拖放控制
54EasyUI 树形菜单- 树形菜单拖放控制
41 0