处理第一个下拉列表的onChange事件

解决方案 »

  1.   

    要向后台提交吗?如果你写在javabean里面的话,那么只能通过submit来传递参数。
    如果不向后台提交的话,只能用javaSript实现。
      

  2.   

    进入页面时,先把数据存到多元数组里边(javascript),然后onChange第一个时调用javascript函数
      

  3.   

    如果你的页面加载没有非常多的动画(也就是说,如果你的页面加载不慢的话),那么,如下的方法是不错的:主题: 为了这个下拉框联动建立一个BEAN.(注:那个BEAN不是用来产生数据的,产生数据的BEAN,,如你所说,已经有了,新建立一个BEAN,专门用来管理显示的)假设: 你当前的页面是  A.JSP, 提交跳转不论, 下拉框的ONCHANGE跳转到下述的ATEMP.JSP文件
          新建立一个页面显示BEAN为:  APAGE.CLASS,  
          新建立一个ATEMP.JSP, 在ATEMP.JSP中有: <JSP:USEBEAN CLASS=APAGE....>,这个文件加载后自动跳转到A.JSP.  选择第一个下拉框后,系统后台走了:  A.JSP--> ATEMP.JSP-->A.JSP
       第二个下拉框的显示内容由APAGE来控制, (APAGE用到的数据不自己产生, 它从SESSION里面取数据.按楼主说, 数据已经在SESSION里面的了)
      

  4.   

    这样看起来繁,已经是最简单的了,如果楼主用JAVASCRIPT来实现联动, 一定会吐血的(至于血是什么颜色的,比如黑色或者绿色,...不得而知)
      

  5.   

    用javascript的onChange比较快,在你的第一个select筐中加入onChange="你写的javascript的function",在你的function中改变第二个select筐的值。
      

  6.   

    不是,就是在客户端,javaScript怎么实现呀。我想问一下,javaScript的变量能不能传到jsp中来。
      

  7.   

    如果你的每一个select筐,选项不多,都是固定的,那比较简单,要是都是从数据库中取出来的,那就需要提交再查库了!
      

  8.   

    用 JavaScript。
    有很多论坛,在注册时填写省市的时候都是这么做的,比如“雷傲论坛”,它是把某个省的所有城市名称放在一个字符串中,中间用一个符号间隔,30几个省的数据放在一个数组中……然后 JavaScript 编写……或者看看俺的方法……
    ---------------------------------------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body>
    <form name="form1" method="post" action="">
     <p>
      <select name="select1" onChange="onOfficeSelectChange();">
      </select>
     </p>
     <p>
    <select name="select2">
      </select>
     </p>
    </form>
    <script language="JavaScript" type="text/JavaScript">function CLabelValue (label, value)
    {
    this.label = label;
    this.value = value;
    }function CSectionOffice (label, value, OfficeID)
    {
    this.label = label;
    this.value = value;
    this.officeID = OfficeID;
    }var theOffices = new Array (3);
    theOffices[0] = new CLabelValue ("&Acirc;&THORN;&ordm;&thorn;&Euml;°&Icirc;&ntilde;&frac34;&Ouml;", "001");
    theOffices[1] = new CLabelValue ("&cedil;&pound;&Igrave;&iuml;&Euml;°&Icirc;&ntilde;&frac34;&Ouml;", "002");
    theOffices[2] = new CLabelValue ("&Eacute;&szlig;&iquest;&Uacute;&Euml;°&Icirc;&ntilde;&frac34;&Ouml;", "003");var theSectionOffices = new Array (10);
    theSectionOffices[0] = new CSectionOffice ("&Acirc;&THORN;&ordm;&thorn;&iquest;&AElig;&Ecirc;&Ograve;1", "001", "001");
    theSectionOffices[1] = new CSectionOffice ("&Acirc;&THORN;&ordm;&thorn;&iquest;&AElig;&Ecirc;&Ograve;2", "002", "001");
    theSectionOffices[2] = new CSectionOffice ("&Acirc;&THORN;&ordm;&thorn;&iquest;&AElig;&Ecirc;&Ograve;3", "003", "001");theSectionOffices[3] = new CSectionOffice ("&cedil;&pound;&Igrave;&iuml;&iquest;&AElig;&Ecirc;&Ograve;1", "004", "002");
    theSectionOffices[4] = new CSectionOffice ("&cedil;&pound;&Igrave;&iuml;&iquest;&AElig;&Ecirc;&Ograve;2", "005", "002");
    //theSectionOffices[5] = new CSectionOffice ("&cedil;&pound;&Igrave;&iuml;&iquest;&AElig;&Ecirc;&Ograve;3", "006", "002");
    theSectionOffices[5] = {label:"&cedil;&pound;&Igrave;&iuml;&iquest;&AElig;&Ecirc;&Ograve;3", value:"006", officeID:"002"};theSectionOffices[6] = new CSectionOffice ("&Eacute;&szlig;&iquest;&Uacute;&iquest;&AElig;&Ecirc;&Ograve;1", "007", "003");
    theSectionOffices[7] = new CSectionOffice ("&Eacute;&szlig;&iquest;&Uacute;&iquest;&AElig;&Ecirc;&Ograve;2", "008", "003");
    //theSectionOffices[8] = new CSectionOffice ("&Eacute;&szlig;&iquest;&Uacute;&iquest;&AElig;&Ecirc;&Ograve;3", "009", "003");
    theSectionOffices[8] = {label:"&Eacute;&szlig;&iquest;&Uacute;&iquest;&AElig;&Ecirc;&Ograve;3", value:"009", officeID:"003"};
    theSectionOffices[9] = new CSectionOffice ("&Eacute;&szlig;&iquest;&Uacute;&iquest;&AElig;&Ecirc;&Ograve;4", "010", "003");
    var aNewElement;
    for (var i=0; i<theOffices.length; i++)
    {
    aNewElement = document.createElement("OPTION");
    aNewElement.text = theOffices[i].label;
    aNewElement.value = theOffices[i].value;document.all.select1.options.add (aNewElement);
    }
    function onOfficeSelectChange ()
    {
    var OfficeID = document.all.select1.value;
    var aNewElement;
    var i;//alert ("you choose: " + OfficeID); // clear old options...
    for (i=document.all.select2.length-1; i>=0; i--)
    document.all.select2.remove (i); // &iquest;&Eacute;&Ograve;&Ocirc;&Acirc;&iuml;&pound;&iquest; // create new options...
    for (i=0; i<theSectionOffices.length; i++)
    {
    if (theSectionOffices[i].officeID == OfficeID)
    {
    aNewElement = document.createElement("OPTION");
    aNewElement.text = theSectionOffices[i].label;
    aNewElement.value = theSectionOffices[i].value;
    document.all.select2.options.add (aNewElement);
    }
    }
    }</script></body>
    </html>
      

  9.   

    机器有问题,从UltraEdit或者editPlus拷贝出来粘贴到记事本中是乱码……
    -------------------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body>
    <form name="form1" method="post" action="">
     <p>
      <select name="select1" onChange="onOfficeSelectChange();" >
      </select>
     </p>
     <p>
    <select name="select2">
      </select>
     </p>
    </form>
    <script language="JavaScript" type="text/JavaScript">function CLabelValue (label, value)
    {
    this.label = label;
    this.value = value;
    }function CSectionOffice (label, value, OfficeID)
    {
    this.label = label;
    this.value = value;
    this.officeID = OfficeID;
    }var theOffices = new Array (3);
    theOffices[0] = new CLabelValue ("罗湖税务局", "001");
    theOffices[1] = new CLabelValue ("福田税务局", "002");
    theOffices[2] = new CLabelValue ("蛇口税务局", "003");var theSectionOffices = new Array (10);
    theSectionOffices[0] = new CSectionOffice ("罗湖科室1", "001", "001");
    theSectionOffices[1] = new CSectionOffice ("罗湖科室2", "002", "001");
    theSectionOffices[2] = new CSectionOffice ("罗湖科室3", "003", "001");theSectionOffices[3] = new CSectionOffice ("福田科室1", "004", "002");
    theSectionOffices[4] = new CSectionOffice ("福田科室2", "005", "002");
    //theSectionOffices[5] = new CSectionOffice ("福田科室3", "006", "002");
    theSectionOffices[5] = {label:"福田科室3", value:"006", officeID:"002"};theSectionOffices[6] = new CSectionOffice ("蛇口科室1", "007", "003");
    theSectionOffices[7] = new CSectionOffice ("蛇口科室2", "008", "003");
    //theSectionOffices[8] = new CSectionOffice ("蛇口科室3", "009", "003");
    theSectionOffices[8] = {label:"蛇口科室3", value:"009", officeID:"003"};
    theSectionOffices[9] = new CSectionOffice ("蛇口科室4", "010", "003");
    var aNewElement;
    for (var i=0; i<theOffices.length; i++)
    {
    aNewElement = document.createElement("OPTION");
    aNewElement.text = theOffices[i].label;
    aNewElement.value = theOffices[i].value;document.all.select1.options.add (aNewElement);
    }
    function onOfficeSelectChange ()
    {
    var OfficeID = document.all.select1.value;
    var aNewElement;
    var i;//alert ("you choose: " + OfficeID); // clear old options...
    for (i=document.all.select2.length-1; i>=0; i--)
    document.all.select2.remove (i); // 可以嘛? // create new options...
    for (i=0; i<theSectionOffices.length; i++)
    {
    if (theSectionOffices[i].officeID == OfficeID)
    {
    aNewElement = document.createElement("OPTION");
    aNewElement.text = theSectionOffices[i].label;
    aNewElement.value = theSectionOffices[i].value;
    document.all.select2.options.add (aNewElement);
    }
    }
    }</script></body>
    </html>
      

  10.   

    单在客户端javaScript的变量是不能传递给jsp的。
    同时,在客户端jsp只是在画面load的时候解析一次,生成静态的html,里面的java source都变成了固定条件下的固定值,无法再进行新的判断,新的操作。
    所以如果想在客户端完成的话,首先在画面load的时候就要把jsp中的数据(多条)传递给javaScript数组,当画面触发了某些事件的时候,由javaScript来作处理。如果你想后台提交的话当我没说。