我主要是这个意思 城市 省份是在A.jsp就是我在这个页面修改个人资料时候选择了相应的城市 省份 点击下一步进入到另外一个b.jsp页面后,然后我想点击上一步回到A.jsp页面 重新选择城市,当我回到A.jsp页面时,显示的就是我刚开始选择的省份 城市

解决方案 »

  1.   

    你在跳转到b.jsp时需要记录下这个选择了的城市和省份,等你点击上一步的时候,再把这个记录的参数带回去,然后就可以处理了。
      

  2.   

    通过request或者 session把选择后的内容传回A.jsp
      

  3.   

    LZ需要那么麻烦吗?用到两jsp页面?
    直接在一个jsp页面中用js函数来实现,当在一个下拉框里面选择了某个省,可以在另外的一个下拉框显示该省的所有城市。这样不就更简单吗?
      

  4.   

    <script type="text/javascript">
     //定义了城市的二维数组,里面的顺序跟省份的顺序是相同的。通过selectedIndex获得省份的下标值来得到相应的城市数组
         var city=[
        ["北京","天津","上海","重庆","香港","澳门"],
         ["石家庄","唐山","秦皇岛","邯郸","邢台","保定","张家口","承德","沧州","廊坊","衡水"],
         ["太原","大同","阳泉","长治","晋城","朔州","晋中","运城","忻州","临汾","吕梁"],
         ["呼和浩特","包头","乌海","赤峰","通辽","鄂尔多斯","呼伦贝尔","巴彦淖尔","乌兰察布","兴安","锡林郭勒","阿拉善"]
    ]
         
     
         function getCity(){
             //获得省份下拉框的对象
             var sltProvince=document.userupdateForm.province;
             //获得城市下拉框的对象
             var sltCity=document.userupdateForm.city;
             
             //得到对应省份的城市数组
             var provinceCity=city[sltProvince.selectedIndex - 1];
     
             //清空城市下拉框,仅留提示选项
           //  sltCity.length=1;
     
             //将城市数组中的值填充到城市下拉框中
             for(var i=0;i<provinceCity.length;i++){
                 sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
             }
         }</script>
      </head>
      <table>
       <form name="userupdateForm">
       <tr><td>请选择企业所在城市<font color="red">*</font></td>
     <td><select name="province" onChange="getCity()">
          <option value="null"  selected="selected">请选择所在省份</option>
            <option value="直辖市">直辖市</option>
            <option value="河北">河北</option>
            <option value="山西">山西</option>
                  </select>
    <select name="city">
           <option selected="selected" value="null">请选择所在城市</option>
           </select><font color="red"><html:errors property="city"/></font></td></tr>
           </table>
       </table>
    这是我的代码 我也知道1 2楼的意思 但是传值要怎么接收了 ?
    3楼还没有明白我的意思.
    我是在b.jsp页面点击上一步 触发了window.history.go(-1)返回这个事件
      

  5.   

    我是在b.jsp页面点击上一步 触发了window.history.go(-1)返回这个事件
    -------------
    这个似乎有点难度,我没有解决过,我觉得你可以直接用链接返回上一步
      

  6.   

    最好是把你选择的省市id都放入session当你点击上一步的时候,肯定是调用上一步的action,在action中根据省的id,再查询一回城市list而当前选择的城市的id已经在session中,拿过来就可以
      

  7.   

    记住历史,并恢复历史似乎可以这样把你的内容放入一个div中然后
    <script language=javascript>
            window.onload = historyOncemore;
    window.onbeforeunload = fixHistory; function fixHistory() //记住历史
    {
    document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
    } function historyOncemore() //恢复历史
    {
    if (document.all("theHistoryRecord").value!="")
    {document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
    }
    }
    </script>
    <div id="thedetailtableDIV">你的内容</div>
    <input name="theHistoryRecord" type=hidden value="">
      

  8.   

    to Landor2004
    采用你的方法 在ie下可以显示 但是遨游 火狐都不能显示 都只是显示出来 请选择所在省份 请选择城市 
      

  9.   

    你的代码修改如下
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>aaa</title><script language=javascript>
    window.onload = historyOncemore;
    window.onbeforeunload = fixHistory; var city=[
           ["北京","天津","上海","重庆","香港","澳门"],
         ["石家庄","唐山","秦皇岛","邯郸","邢台","保定","张家口","承德","沧州","廊坊","衡水"],
         ["太原","大同","阳泉","长治","晋城","朔州","晋中","运城","忻州","临汾","吕梁"],
         ["呼和浩特","包头","乌海","赤峰","通辽","鄂尔多斯","呼伦贝尔","巴彦淖尔","乌兰察布","兴安","锡林郭勒","阿拉善"]
    ]
         
     
         function getCity(){
             //获得省份下拉框的对象
             var sltProvince=document.userupdateForm.province;
             //获得城市下拉框的对象
             var sltCity=document.userupdateForm.city;
             
             //得到对应省份的城市数组
             var provinceCity=city[sltProvince.selectedIndex - 1];
     
             //清空城市下拉框,仅留提示选项
           //  sltCity.length=1;
     
             //将城市数组中的值填充到城市下拉框中
             for(var i=0;i<provinceCity.length;i++){
                 sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
             }
         } function fixHistory() //记住历史
    {
    document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
    } function historyOncemore() //恢复历史
    {
    if (document.all("theHistoryRecord").value!="")
    {document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
    }
    } function selectallcheckbox(obj) //全选或全不选
    {
    var tureorfalse=obj.checked;
    var theDetail=tbDetailUsed.rows;
    for(var i=0;i<theDetail.length-1;i++)
    {
    theDetail[i].all("record_select").checked=tureorfalse;
    }
    }
    function submitProcess()
    {
      document.userupdateForm.submit();
    }
    </script>
    </head><body>
    <form name="userupdateForm" action="about:结果页面">
    <input type="button"  value="完成" class="bottom" onclick="submitProcess();">
    <div width=100% id=thedetailtableDIV>
    <select name="province" onChange="getCity()">
    <option value="null"  selected="selected">请选择所在省份</option>
    <option value="直辖市">直辖市</option>
    <option value="河北">河北</option>
    <option value="山西">山西</option>
    </select>
     <select name="city">
    <option selected="selected" value="null">请选择所在城市</option>
    </select><font color="red"><html:errors property="city"/></font></td></tr>
    </div>
    </form>
    <input name="theHistoryRecord" type=hidden value="">
    </body></html>
      

  10.   

    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
     
        
        <title>updateuser</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">
    --><script type="text/javascript">
    window.onload = historyOncemore;
        window.onbeforeunload = fixHistory;
     //定义了城市的二维数组,里面的顺序跟省份的顺序是相同的。通过selectedIndex获得省份的下标值来得到相应的城市数组
         var city=[
        ["北京","天津","上海","重庆","香港","澳门"],
         ["石家庄","唐山","秦皇岛","邯郸","邢台","保定","张家口","承德","沧州","廊坊","衡水"],
         ["太原","大同","阳泉","长治","晋城","朔州","晋中","运城","忻州","临汾","吕梁"],
         ["呼和浩特","包头","乌海","赤峰","通辽","鄂尔多斯","呼伦贝尔","巴彦淖尔","乌兰察布","兴安","锡林郭勒","阿拉善"]
             ];
     
       function getCity(){
             //获得省份下拉框的对象
             var sltProvince=document.userupdateForm.province;
             //获得城市下拉框的对象
             var sltCity=document.userupdateForm.city;
             
             //得到对应省份的城市数组
             var provinceCity=city[sltProvince.selectedIndex - 1];
     
             //清空城市下拉框,仅留提示选项
           //  sltCity.length=1;
     
             //将城市数组中的值填充到城市下拉框中
             for(var i=0;i<provinceCity.length;i++){
                 sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
             }
         }    function fixHistory()                            //记住历史
        {
                document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
        }    function historyOncemore()                        //恢复历史
        {
            if (document.all("theHistoryRecord").value!="")
                {document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
                }
        }    function selectallcheckbox(obj)                    //全选或全不选
        {
            var tureorfalse=obj.checked;
            var theDetail=tbDetailUsed.rows;
            for(var i=0;i<theDetail.length-1;i++)
            {
                theDetail[i].all("record_select").checked=tureorfalse;
            }
        }
        function submitProcess()
        {
          document.userupdateForm.submit();
        }</script>
      </head>
      <body>
    <table width="990" height="750">
    <tr><logic:iterate id="user" name="userdata" scope="session">
    <td width="200"><jsp:include page="/jsp/menu.jsp" flush="true"/></td>
    <td align="center" valign="top"><table align="center">
    <html:form action="/userupdate" method="post"  onsubmit="return validateuserupdateForm(this)" focus="companyname"> 
     <tr><td>用户名  <font color="red">*</font></td>
     <td><html:text property="username" disabled="true" value="${user.udName}"/><FONT color="red"><html:errors property="username"/></FONT></td></tr>
     <tr><td>请选择企业所在行业<font color="red">*</font></td>
     <td><select name="business">
     <option value="null" selected="selected">请选择</option>
     <option value="医药卫生">医药卫生</option>
     <option value="建筑建材">建筑建材</option>
     <option value="冶金矿产">冶金矿产</option>
     <option value="石油化工">石油化工</option>
     </select><font color="red"><html:errors property="business"/></font></td>
     </tr>
     <tr><td>请选择企业所在城市<font color="red">*</font></td>
     <td><div width=100% id=thedetailtableDIV><select name="province" onChange="getCity()">
          <option value="null"  selected="selected">请选择所在省份</option>
            <option value="直辖市">直辖市</option>
            <option value="河北">河北</option>
            <option value="山西">山西</option>
           <option value="内蒙古">内蒙古</option>
                      
           </select>
    <select name="city">
           <option selected="selected" value="null">请选择所在城市</option>
           </select><font color="red"><html:errors property="city"/></font></td></tr></div> 
      <tr><td>请输入企业地址  </td>
     <td><html:text property="companydress" value="${user.udCompdress}"/><font color="red"><html:errors property="companydress"/></font></td></tr>
    <tr><td colspan="2" align="center">
     <html:hidden property="status" value="update"/>
     <html:hidden property="username" value="${user.udName}"/>
     <html:submit property="update"  value="提交更改" onclick="submitProcess();" />
     <input name="theHistoryRecord" type=hidden value=""> 
     </td></tr>
    </html:form> </table>
    </td></logic:iterate></tr>
    </table>
     <
     <input name="theHistoryRecord" type=hidden value="">
    </body>
    </html>我的jsp页面是这么修改的 可是显示不出来。
      

  11.   

    参考http://hahaxiao.net/faces/website/website.jsp?id=14
      

  12.   

    把document.all什么的都改成document.getElementById("xxx");
    <input id="theHistoryRecord" name="theHistoryRecord" type=hidden value="">看看
      

  13.   

    测试了一下,两个下拉框的内容在firefox和ie上都可以保存,默认的selected在ie下是可以默认到的,但是在firefox上没默认出来,所以两个都是“请选择...”但是里面的内容是对的,再研究研究,呵呵
      

  14.   

    手工记录一下selectIndex,测试通过,楼主可以参考一下
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>aaa</title><script language=javascript>
    window.onload = historyOncemore;
    window.onbeforeunload = fixHistory; var city=[
           ["北京","天津","上海","重庆","香港","澳门"],
         ["石家庄","唐山","秦皇岛","邯郸","邢台","保定","张家口","承德","沧州","廊坊","衡水"],
         ["太原","大同","阳泉","长治","晋城","朔州","晋中","运城","忻州","临汾","吕梁"],
         ["呼和浩特","包头","乌海","赤峰","通辽","鄂尔多斯","呼伦贝尔","巴彦淖尔","乌兰察布","兴安","锡林郭勒","阿拉善"]
    ]
         
     
         function getCity(t){

    alert(document.getElementById("province").selectedIndex)
             //获得省份下拉框的对象
             var sltProvince=document.userupdateForm.province;
             //获得城市下拉框的对象
             var sltCity=document.userupdateForm.city;
             
             //得到对应省份的城市数组
             var provinceCity=city[sltProvince.selectedIndex - 1];
     
             //清空城市下拉框,仅留提示选项
           //  sltCity.length=1;
     
             //将城市数组中的值填充到城市下拉框中
             for(var i=0;i<provinceCity.length;i++){
                 sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
             }
         }
     function getSelfCity(t){
    alert(document.getElementById("city").selectedIndex)
         } function fixHistory() //记住历史
    {
    document.getElementById("theHistoryRecord").value=document.getElementById("thedetailtableDIV").innerHTML.replace(/\n/g,"");
    document.getElementById("index1").value = document.getElementById("province").selectedIndex;
    document.getElementById("index2").value = document.getElementById("city").selectedIndex;
    } function historyOncemore() //恢复历史
    {
    if (document.getElementById("theHistoryRecord").value!="")
    {
    document.getElementById("thedetailtableDIV").innerHTML=document.getElementById("theHistoryRecord").value;
    document.getElementById("province").selectedIndex = document.getElementById("index1").value;
    document.getElementById("city").selectedIndex = document.getElementById("index2").value;
    }
    } function submitProcess()
    {
      document.userupdateForm.submit();
    }
    </script>
    </head><body>
    <form name="userupdateForm" action="hehee.html">
    <input type="button"  value="完成" class="bottom" onclick="submitProcess();">
    <div width=100% id="thedetailtableDIV">
    <select id="province" name="province" onChange="getCity(this)">
    <option value="" >请选择所在省份</option>
    <option value="直辖市">直辖市</option>
    <option value="河北">河北</option>
    <option value="山西">山西</option>
    </select>
     <select  id="city" name="city" onChange="getSelfCity(this)">
    <option  value="">请选择所在城市</option>
    </select></td></tr>
    </div></form>
    <input name="theHistoryRecord"  id="theHistoryRecord" type=hidden value="">
    <input name="index1"  id="index1" type=hidden value="">
    <input name="index2"  id="index2" type=hidden value="">
    </body></html>
      

  15.   

    这里的
    onload 
    getElementById
    innerHTML
    似乎各大浏览器都支持而firefox和IE两个浏览器都支持onbeforeunload 事件,傲游是ie内核呀,所以肯定支持