在刷新时保留下拉列表选择 [英] retain dropdown selection on refresh

查看:119
本文介绍了在刷新时保留下拉列表选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我有当用户选择该选项时的下拉菜单,该值将传递到与查询字符串刷新页面相同的URL。页面刷新后,我想保留所选值,以便用户知道所选的内容。如何在jquery中执行此操作?

I have a dropdown when user selects the option, the value is passed on to the same url as querystring refreshing the page. after the page refreshes i wanna retain the selected value so user knows what was selected. How do i do this in jquery?

<select id="hospitalDropDown" onchange="window.open(this.options[this.selectedIndex].value,'_top')"> 
        <option value="http://mysite.com/events/Pages/default1.aspx">All Hospitals</option>
  <option value="http://mysite.com/events/Pages/default1.aspx?hos=Dyer">Dyer</option>
  <option value="http://mysite.com/events/Pages/default1.aspx?hos=Carmel">Carmel</option>
</select>

基本上,逻辑是在一些变量中隐藏选择,并将其作为选择等于true传递,但我不是能够在jquery中做到这一点...我没有服务器端代码。

Basically the logic is trap the selection in some variable and pass it as selected equals true but i am not being able to do it in jquery..I don't have acccess to server side code..either

推荐答案

方法你可以设置一个cookie

For a clean method you can set a cookie

查看以下问题和回复

jQuery Cookie设置在页面刷新后选择下拉值

*但我最喜欢的是使用ajax方法在用户会话中设置选择。

*But my favorite is to set the selection in the user session using ajax method.

这篇关于在刷新时保留下拉列表选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆