我想做一个二级联动的选择框,其值要查数据库中的两个表得到,请问哪位高手可以帮忙写一个简单易懂的例子啊,急……

解决方案 »

  1.   

    现在可能很多人要说ajax吧。我是不喜欢
    google一下吧,二级联动,直接JavaScript就可以了。
      

  2.   

    用js控制select的onchange事件,加入一些java查询代码,不难啊```用什么数据库啊`
      

  3.   

    http://blog.csdn.net/guixiang155cm/archive/2009/07/04/4321673.aspx这里有 
      

  4.   

    我有现成的,可是用的是一个表,用的是dwr,hibernate,spring
      

  5.   

    大致过程:
    <select onchange="aa();">
       <option value="1" selected="selected">aa</option>
       <option value="2">bb</option>
       <option value="3">cc</option>
    </select>
    <select id="dd">
       <option value="" selected="selected">haha</option>
    </select>
    function aa(){
       //创建XMLHTTPREQUEST对象
       if(xmlHttp){
         var url = "";
         xmlHttp.onreadystatechange = haha;
         xmlHttp.open("GET",url,true);
         xmlHttp.send(null);
       }else{
         alert("请求异常!");
       }
    }
    function haha(){
      if(xmlHttp.readyState==4){
        if(xmlHttp.status==200){
          //解析服务器端传过来的数据
          用document.getElementById("dd").options[i]=new Option(para1,value2);给第二个下拉列表值
        }
      }
    }
      

  6.   

    数据量大的还是用ajax吧,楼上的已经给出例子了
    数据量小的用js就可以<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD>
    <script type="text/javascript">
    function province(proid,proname){
    this.proid = proid;
    this.proname = proname;
    }
    function city(cityid,cityname,proid){
    this.cityid = cityid;
    this.cityname = cityname;
    this.proid = proid;
    }
    var proArray = new Array();
    proArray.push(new province("1","湖北"));
    proArray.push(new province("2","湖南"));
    proArray.push(new province("3","河南"));
    var cityArray = new Array();
    cityArray.push(new city("1","武汉","1"));
    cityArray.push(new city("2","黄石","1"));
    cityArray.push(new city("3","宜昌","1"));
    cityArray.push(new city("4","黄冈","1"));
    cityArray.push(new city("5","襄樊","1"));
    cityArray.push(new city("6","长沙","2"));
    cityArray.push(new city("7","岳阳","2"));
    cityArray.push(new city("8","湘潭","2"));
    cityArray.push(new city("9","郴州","2"));
    cityArray.push(new city("10","郑州","3"));
    cityArray.push(new city("11","信阳","3"));
    cityArray.push(new city("12","洛阳","3"));
    function change(pro,city){
    var selectpro=pro.options[pro.selectedIndex].value;
    while(city.options.length>0){
    city.options[0]=null;
    }
    for(i=0;i<cityArray.length;i++){
    if(cityArray[i].proid == selectpro){
    city.options.add(new Option(cityArray[i].cityname,cityArray[i].cityid));
    }
    }
    }
        function initApp(){
    var pro = document.form1.pro;
    for(var i = 0; i<proArray.length;i++){
    pro.options.add(new Option(proArray[i].proname,proArray[i].proid))
    }
    var city = document.form1.city;
    change(pro,city);
    }
     </script>
     <BODY onload = "initApp();">
      <form name = "form1">
      省<select name="pro"  onchange="change(this,this.form.city)"></select>&nbsp;&nbsp;&nbsp;&nbsp;
      市<select name ="city"></select>
      </form>
     </BODY>
    </HTML>