Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408622
  • 博文数量: 114
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1395
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-05 17:54
文章分类

全部博文(114)

文章存档

2011年(2)

2009年(1)

2008年(111)

我的朋友

分类: Java

2008-07-12 22:25:24

 

JSP+JavaScript打造二级级联下拉菜单:

class(一级栏目信息):classId(自动编号),className(栏目名称), Nclass(二级栏目信息), NclassId(自动编号),NclassName(栏目名称),parentId(一级栏目id,与class表中的classId关联)

<%@ page contentType=text/html; charset=GB2312 language=java errorPage=../error.jsp %>
<%@ include file=../conn.jsp%>
<%@ include file=../ds.jsp%>
<%@ taglib uri=http:>
<%request.setCharacterEncoding(gb2312); %>
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html; charset=gb2312>

<TITLE>级联菜单</TITLE>
<LINK rel=stylesheet type=text/css href=style.css>
</HEAD>

<%String sql=select * from Nclass order by NclassId asc;
ResultSet rs=stmt.executeQuery(sql);
%>

<script type=text/javascript>
var onecount;
onecount=0;
subcat = new Array();
        <%
        int count = 0;
        while(rs.next()){
        %>
subcat[<%=count%>] = new Array(<%=rs.getString(NclassName)%>,
<%=rs.getString(NclassId)%>,<%=rs.getString(parentId)%>);
        <%
        count++;
        }
        rs.close();
        %>
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.myform.NclassId.length = 0;

    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][2] == locationid)
            {
                document.myform.NclassId.options[document.myform.NclassId.length] = new
Option(subcat[i][0], subcat[i][1]);
            }
        }
        
    }
</script>

<FORM method=POST name=myform action=adminsave.jsp?action=add>
  <TABLE>
   
    <TR>
      <TD>一级分类</TD>
      <TD>
        <SELECT name=classId onChange=changelocation(document.myform.classId.options
[document.myform.classId.selectedIndex].value) size=1>
          <OPTION selected value>==请选一级分类==</OPTION>
        <sql:query var=query dataSource=$>
          SELECT * FROM class
       </sql:query>
<c:forEach var=row items=$>
 <option value=$>$</option>
</c:forEach>
</select>
      </TD>
      <TD>选择二级分类</TD>
      <TD>
        <SELECT name=NclassId>
          <OPTION selected value>==请选二级分类==</OPTION>
        </SELECT>
      </TD>
    </TR>
</TABLE>
  
</FORM>
</BODY>
</HTML>
<%@ page contentType=text/html; charset=GB2312 language=java errorPage=../error.jsp %>
<%@ include file=../conn.jsp%>
<%@ include file=../ds.jsp%>
<%@ taglib uri=http:>
<%request.setCharacterEncoding(gb2312); %>
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html; charset=gb2312>

<TITLE>级联菜单</TITLE>
<LINK rel=stylesheet type=text/css href=style.css>
</HEAD>

<%String sql=select * from Nclass order by NclassId asc;
ResultSet rs=stmt.executeQuery(sql);
%>

<script type=text/javascript>
var onecount;
onecount=0;
subcat = new Array();
        <%
        int count = 0;
        while(rs.next()){
        %>
subcat[<%=count%>] = new Array(<%=rs.getString(NclassName)%>,
<%=rs.getString(NclassId)%>,<%=rs.getString(parentId)%>);
        <%
        count++;
        }
        rs.close();
        %>
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.myform.NclassId.length = 0;

    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][2] == locationid)
            {
                document.myform.NclassId.options[document.myform.NclassId.length] = new
Option(subcat[i][0], subcat[i][1]);
            }
        }
        
    }
</script>

<FORM method=POST name=myform action=adminsave.jsp?action=add>
  <TABLE>
   
    <TR>
      <TD>一级分类</TD>
      <TD>
        <SELECT name=classId onChange=changelocation(document.myform.classId.options
[document.myform.classId.selectedIndex].value) size=1>
          <OPTION selected value>==请选一级分类==</OPTION>
        <sql:query var=query dataSource=$>
          SELECT * FROM class
       </sql:query>
<c:forEach var=row items=$>
 <option value=$>$</option>
</c:forEach>
</select>
      </TD>
      <TD>选择二级分类</TD>
      <TD>
        <SELECT name=NclassId>
          <OPTION selected value>==请选二级分类==</OPTION>
        </SELECT>
      </TD>
    </TR>
</TABLE>
  
</FORM>
</BODY>
</HTML>

阅读(864) | 评论(1) | 转发(0) |
0

上一篇:JSP登陆系统详解

下一篇:JavaMail会话

给主人留下些什么吧!~~

chinaunix网友2008-07-15 20:29:21

很好。。谢谢!!帮了我很大的忙!