日期:2014-05-16  浏览次数:20344 次

如何让页面刷新后所选下拉列表框的值不变
现在我有一个下拉列表框,每次选择一个值以后就要刷新页面,然后所选的值就变为初始状态,有没有什么办法让刷新后所选的值不会改变。
代码如下:
<select id="id" name="nian" size="1" onChange="window.location.href='KHList.asp?id=<%=depid%>&nian='+(this.options[this.selectedIndex].value);">
  <option value="" selected>请选择考核年份</option>
  <option <%if nian=year(now()) then%>selected<%end if%> value="<%=year(now())%>"><%=year(now())%>年</option>
  <option <%if nian=year(now())-1 then%>selected<%end if%> value="<%=year(now())-1%>"><%=year(now())-1%>年</option>
  <option <%if nian=year(now())-2 then%>selected<%end if%> value="<%=year(now())-2%>"><%=year(now())-2%>年</option>
  <option <%if nian=year(now())-3 then%>selected<%end if%> value="<%=year(now())-3%>"><%=year(now())-3%>年</option>
  <option <%if nian=year(now())-4 then%>selected<%end if%> value="<%=year(now())-4%>"><%=year(now())-4%>年</option>
</select>

------解决方案--------------------
<%
nian=request("nian")
if not isnumeric(nian) or nian="" then nian=year(date)
nian = cint(nian)
%>
<select id="id" name="nian" size="1" onChange="window.location.href='KHList.asp?id=<%=depid%>&nian='+(this.options[this.selectedIndex].value);">
  <option value="" selected>请选择考核年份</option>
  <option <%if nian=year(now()) then%>selected<%end if%> value="<%=year(now())%>"><%=year(now())%>年</option>
  <option <%if nian=year(now())-1 then%>selected<%end if%> value="<%=year(now())-1%>"><%=year(now())-1%>年</option>
  <option <%if nian=year(now())-2 then%>selected<%end if%> value="<%=year(now())-2%>"><%=year(now())-2%>年</option>
  <option <%if nian=year(now())-3 then%>selected<%end if%> value="<%=year(now())-3%>"><%=year(now())-3%>年</option>
  <option <%if nian=year(now())-4 then%>selected<%end if%> value="<%=year(now())-4%>"><%=year(now())-4%>年</option>
</select>
------解决方案--------------------
$("select1").find("option[value=3]").attr("checked",true);
------解决方案--------------------
根据楼主的要求,可能cookie是比较好的解决方法,把每次选好的值放到cookie里,等页面刷新完了再重新读取cookie值,赋值给select
------解决方案--------------------
基本上就是三种保存上一页面数据的方式的选择,看那种更合适你现在的程序;

1.cookie
2.url
3.hidden表单