假设我有下面一个下拉菜单,我想在当前页面选中的值按提交后(提交的处理页为当前页),如何能让这个菜单默认显示的是刚刚提交的选项。假如我选择2的时候按提交,然后提交到当前页面这个select显示的默认值就为刚刚提交的2 ,现在这个下拉菜单一直默认显示第一行的值。
<select name="select">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>

解决方案 »

  1.   

    判断几次就好了
    判断那个值是几,就让他设为默认选项
    <c:choose>
    <c:when test="${param.select==1}">
    <select name="select">
      <option value="1" selected="selected">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
    </select>
    </c:when>
    <c:when test="${param.select==2}">
    <select name="select">
      <option value="1">1</option>
      <option value="2" selected="selected">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
    </select>
    </c:when>
    <c:when test="${param.select==3}">
    <select name="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3"  selected="selected">3</option>
      <option value="4">4</option>
    </select>
    </c:when><c:when test="${param.select==4}">
    <select name="select">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4"  selected="selected">4</option>
    </select>
    </c:when>
    </c:choose>
      

  2.   

    1楼没看明白我意思吗? 我举个实际点的。比我下拉菜单有几个班级,我选择其中一个,就查询数据库的值显示。<select name="select">
      <option >请选择年纪</option>
      <option value="一年">一年级</option>
      <option value="二年级">二年级</option>
      <option value="三年级">三年级</option>
      <option value="四年级">四年级</option>
    </select>当我选择三年级,然后按查询,页面就会显示数据等于三年级的数据。但是每次提交查询后,或者刷新页面后,这个select的下拉菜单默认显示的都是第一行,我希望能在提交之后,显示我所选择的,如我选择三年级提交后,这个select的默认就显示我刚刚选择提交的那一个。
      

  3.   

    js控制。
    加上docment.all.select.value = 'X年纪';
      

  4.   


    <select name="select">
      <option value="1" ${param.select==1?"selected":"">1</option>
      <option value="2" ${param.select==2?"selected":"">2</option>
      <option value="3" ${param.select==3?"selected":"">3</option>
      <option value="4" ${param.select==4?"selected":"">4</option>
    </select>
      

  5.   

    扫帖一族来了!
    您的问题可以抽象为:
    a页面跳转到a页面,刷新后记住上一个页面a的状态关于记住上个页面的参数问题,有N中方法,给你推荐两种:方法一:表单提交:
    select下拉单作为一个form元素提交,在网页Head头中加入
     <script>
       var select_status = <%=request.getParameter("selelctname")%>
       setTimeout(function(){ document.getElementById("selelctid").value=select_status},500);
    </script>方法二:将状态保存在本地cookie
     <script>
      vat flag = document.cookie.indexof("selelct_value");
      if(flag==-1){
       var s = new Date().getTime()+15*60+1000;
       document.cookie = "selelct_value="+document.getElementById("selelctid").value+";expires="+s.toGMTString();
    }else{
      document.getElementById("selelctid").value=document.cookie.match(/selelct_value=(.+);/g)[1]
    }
    </script>代码没测,不过基本思路绝对正确!
      

  6.   

    扫帖一族来了!
    您的问题可以抽象为:
    a页面跳转到a页面,刷新后记住上一个页面a的状态关于记住上个页面的参数问题,有N中方法,给你推荐两种:方法一:表单提交:
    select下拉单作为一个form元素提交,在网页Head头中加入
     <script>
       var select_status = <%=request.getParameter("selelctname")%>
       setTimeout(function(){ document.getElementById("selelctid").value=select_status},500);
    </script>方法二:将状态保存在本地cookie
     <script>
      vat flag = document.cookie.indexof("selelct_value");
      if(flag!=-1){
     document.getElementById("selelctid").value=document.cookie.match(/selelct_value=(.+);/g)[1];
    }
       var s = new Date().getTime()+15*60+1000;
       document.cookie = "selelct_value="+document.getElementById("selelctid").value+";expires="+s.toGMTString(); 
    }
    </script>代码没测,不过基本思路绝对正确!