日期:2014-05-17  浏览次数:20700 次

jsp做一个二级下拉菜单,有问题了~~
小妹用最简单的方法做一个二级联动下拉菜单,从数据库中取数作为选项。但是一级选项还能出来,选好一级选项后二级选项出不来。劳烦各位大虾帮我看看,谢谢了~~
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8" session="true"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
<%
      String SqlQuery="SELECT * FROM binary_system";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/zhengshi","root","zky");
         Statement sql=conn.createStatement();
         ResultSet rs=sql.executeQuery(SqlQuery);
%>
<script type="text/javascript"> 
var onecount; 
onecount=0; 
subcat = new Array(); 
        <% 
        int count = 0; 
        while(rs.next()){ 
        %> 
subcat[<%=count%>] = new Array("<%=rs.getString("element1")%>",
"<%=rs.getString("element2")%>","<%=rs.getString("phase")%>"); 
        <% 
        count++; 
        } rs.close();
        %> 
onecount=<%=count%>; 
 
function select1(locationid) 
    { 
    document.myform.erji.length = 0; 
    
    var i; 
    for (i=0;i < onecount; i++) 
        { 
            if (subcat[i][0].equals(locationid)) 
            { 
                document.myform.erji.options[document.myform.erji.length] = new 
Option(subcat[i][1]); 
            }        
        }
&nb