联级菜单

function on_trview(trname,enforce)
{
 
 <%
 for(int i=0; i<topCategories.size(); i++) {
  Category c = topCategories.get(i); 
 %>
  document.all.pma_<%=c.getId()%>.style.display="none";
 <%
 }
 %>
 
 
 if (enforce=="in")
 {
     //eval里的代码当做javascript代码执行一遍
  eval("document.all.pma_"+trname+".style.display=''");
  //eval("alert()");
  //ruby on rails
 }
}

 

//获取顶级菜单
private List<Category> getTopCategories(List<Category> categories) {
  List<Category> topCategories = new ArrayList<Category>();
  for (int i = 0; i < categories.size(); i++) {
   Category c = categories.get(i);
   if (c.getGrade() == 1) {
    topCategories.add(c);
   }
  }
  return topCategories;
 }

 

//获取相应的子菜单列表

 private List<Category> getChilds(Category parent, List<Category> categories) {
  List<Category> childs = new ArrayList<Category>();
  for (int i = 0; i < categories.size(); i++) {
   Category c = categories.get(i);
   if (c.getPid() == parent.getId()) {
    childs.add(c);
   }
  }
  return childs;
 }

 

//获取子菜单

 private String getChildsStr(List<Category> childs) {
  StringBuffer buf = new StringBuffer();
  for (int i = 0; i < childs.size(); i++) {
   Category c = childs.get(i);
   buf.append(
     "<a href='ShowProducts.jsp?categoryId=" + c.getId() + "'>")
     .append(c.getName()).append("</a>").append("-");
  }
  return buf.toString();
 }

 


<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
   <td align="left" background="images/topbg.gif" valign="middle"width="897">
    <table align="left" border="0" cellpadding="0" cellspacing="0"width="713">
      <tr class="style1" align="center">
       <td align="left">
       <!-- 显示第一层目录 -->
        <%
         for (int i = 0; i < topCategories.size(); i++) {
          Category c = topCategories.get(i);
        %>
        <a href="" onMouseOver="on_trview(<%=c.getId()%>,'in')">
         <!--<img src="images/00.gif" name="Image0" border="0">-->
         <span style="color: #FFFFFF"><%=c.getName()%>
         </span>
        </a>
        <%
         }
        %>
       </td>
      </tr>
    </table>
   </td>
  </tr>
  <tr>
   <td colspan="2">
    <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
      <tr>
       <td background="images/topbg2.gif" height="25">
        <table style="border-collapse: collapse;" class="twoji"
         border="0" cellpadding="0" cellspacing="0" width="100%">
          <%
           for (int i = 0; i < topCategories.size(); i++) {
            Category parent = topCategories.get(i);
            List<Category> childs = getChilds(parent, categories);
          %>
          <tr id="pma_<%=parent.getId()%>" style="display: none;">
           <td style="position: relative; left: 0pt;" height="25"
            width="100%">
            &nbsp;
            <%=getChildsStr(childs)%>
           </td>
          </tr>
          <%
           }
          %>
        </table>
       </td>
      </tr>
    </table>
   </td>
  </tr>
</table>

阅读更多
想对作者说点什么? 我来说一句

三级级联菜单(JS+HTML)

2016年01月21日 2KB 下载

动态联级菜单js文件

2009年09月17日 7KB 下载

无限级树形菜单(Sql数据库)

2007年12月14日 429KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭