<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一、在數(shù)據(jù)庫(kù)數(shù)據(jù)庫(kù)中建立三個(gè)表
    1.city
    字段:
    districtname,locationid,districtid
    2.province
    字段:
    locationid,locationname
    3.village
    字段:
    villageid,villagename,districtid
    二、代碼如下:
    <%@ page language="java" contentType="text/html; charset=gb2312"
    ??? pageEncoding="gb2312"%>
    <%@ page import="java.sql.* "%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>jsp實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)的下拉列表框效果</title>
    <%
    ?? Connection conn=null;
    ?? Statement stmt=null;
    ?? ResultSet rs=null,rs1=null,rs2=null;
    ?? String sql;
    ?? int count;
    ?? int count2;
    ?? String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
    ?? String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=SJLD";
    ?? try{
    ??? Class.forName(drivername);
    ??? conn=DriverManager.getConnection(url,"sa","");
    ??? stmt=conn.createStatement();
    ??? sql="select * from city order by locationid asc";
    ??? rs=stmt.executeQuery(sql);
    ?? }catch(SQLException e){
    ??? System.out.println(e.getMessage());
    ?? }
    ??
    %>
    <script language="javascript">
    var onecount;
    onecount=0;
    subcat=new Array();
    <%
    count=0;
    while(rs.next()){
    ?%>
    ?subcat[<%=count%>]=new Array("<%=rs.getString("districtname")%>","<%=rs.getInt("locationid")%>","<%=rs.getInt("districtid")%>");
    ?<%
    ?count = count + 1 ;

    }
    rs.close();
    rs=null;
    %>
    onecount=<%=count%>;
    function changelocation(locationid){
    document.myform.smalllocation.length=0;
    var locationid=locationid;
    var i;
    document.myform.smalllocation.options[0]=new Option('==所選城市的地區(qū)==','');
    for(i=0;i<onecount;i++){
    if (subcat[i][1] == locationid)
    {
    document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);
    }
    }

    ??
    }
    </script>
    <%
    ?sql="select * from village order by districtid asc";
    ?rs2=stmt.executeQuery(sql);
    %>
    <script language="javascript">
    var onecount2;
    onecount2=0;
    subcat2=new Array();
    <%
    count2=0;
    while(rs2.next()){
    ?%>
    ?subcat2[<%=count2%>]=new Array("<%=rs2.getString("villagename")%>","<%=rs2.getInt("districtid")%>","<%=rs2.getInt("villageid")%>");
    ?<%
    ?count2 = count2 + 1 ;

    }
    rs2.close();
    rs2=null;
    %>
    onecount2=<%=count2%>;
    function changelocation2(districtid)
    {
    document.myform.village.length = 0;

    var districtid=districtid;
    var j;
    document.myform.village.options[0] = new Option('==所選地區(qū)的縣區(qū)==','');
    for (j=0;j < onecount2; j++)
    {
    ? if (subcat2[j][1] == districtid)
    ?{
    ? document.myform.village.options[document.myform.village.length] = new Option(subcat2[j][0], subcat2[j][2]);
    ? }
    }

    }
    </script>

    </head>
    <body>
    <form name="myform" method="post">
    分類:<select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)" size="1">
    <option selected>請(qǐng)選擇你所在的省份</option>
    <%
    ? sql ="select * from province order by locationname asc";
    ?rs1 = stmt.executeQuery(sql);
    ?while(rs1.next()){
    ?%>
    ?<option value="<%=rs1.getInt("locationid")%>"><%=rs1.getString("locationname")%></option>

    ?<% }
    ?
    ?
    ?rs1.close();
    ?rs1 = null;
    ?conn.close();
    ?conn =null;


    %>
    </select><select name="smalllocation" onChange="changelocation2(document.myform.smalllocation.options[document.myform.smalllocation.selectedIndex].value)">
    <option selected value="">==所有地區(qū)==</option>
    </select><select name="village" size="1">
    <option selected>==所有縣區(qū)==</option>
    </select>
    </form>

    </body>
    </html>

    Feedback

    # re: 用JSP實(shí)現(xiàn)下拉列表框三級(jí)聯(lián)動(dòng)效果  回復(fù)  更多評(píng)論   

    2007-06-06 17:39 by Carja
    能運(yùn)行嗎?我看蠻好的!

    # re: 用JSP實(shí)現(xiàn)下拉列表框三級(jí)聯(lián)動(dòng)效果  回復(fù)  更多評(píng)論   

    2007-09-18 10:18 by Vivion
    謝謝樓主分享!

    # re: 用JSP實(shí)現(xiàn)下拉列表框三級(jí)聯(lián)動(dòng)效果  回復(fù)  更多評(píng)論   

    2007-11-11 12:38 by programmer
    真的很好,先謝謝了哦

    # re: 用JSP實(shí)現(xiàn)下拉列表框三級(jí)聯(lián)動(dòng)效果  回復(fù)  更多評(píng)論   

    2008-05-02 21:10 by 讓我慢慢的靠近你 以后告訴你
    可不可以只建一張表啊?加我QQ哈 564757891 我愛(ài)你~!! 呵呵

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    posts - 146, comments - 143, trackbacks - 0, articles - 0

    Copyright © flustar

    主站蜘蛛池模板: 国产免费AV片在线观看| 亚洲熟妇无码另类久久久| 免费精品一区二区三区第35| 亚洲一区二区三区成人网站| 国产成人精品日本亚洲| 亚洲Av无码乱码在线观看性色 | 99久久久国产精品免费无卡顿| 美女被爆羞羞网站在免费观看 | 久久成人免费播放网站| 免费毛片毛片网址| 亚洲影视自拍揄拍愉拍| 久久久青草青青亚洲国产免观 | 亚洲精华国产精华精华液好用| 亚洲人成亚洲精品| 久久综合亚洲色HEZYO国产| 四虎成人免费观看在线网址| 在线播放亚洲第一字幕| 在线观看亚洲免费| 毛片免费全部播放一级| 四虎永久在线精品免费观看视频| 日本免费在线中文字幕| 好猛好深好爽好硬免费视频| 理论亚洲区美一区二区三区| 亚洲中文字幕无码av| 亚洲女人18毛片水真多| 亚洲美女自拍视频| 亚洲国产成人私人影院| 亚洲无人区一区二区三区| 亚洲高清最新av网站| 亚洲国产精品成人久久蜜臀| 国产男女猛烈无遮挡免费视频| 午夜成年女人毛片免费观看| 日韩精品无码区免费专区| 2021久久精品免费观看| 4455永久在线观免费看| 国产精品视频免费| 亚洲啪啪免费视频| 中文毛片无遮挡高潮免费| 免费福利在线播放| 桃子视频在线观看高清免费完整| 中文字幕av无码无卡免费|