刷新时保留下拉选择
可能的重复:
在回发时保留选定的下拉选项
当用户选择该选项时,我有一个下拉菜单,该值将传递到与刷新页面的查询字符串相同的 url。页面刷新后,我想保留所选值,以便用户知道选择了什么。我如何在 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 中执行此操作。我无法访问服务器端代码。
Possible Duplicate:
retaining selected dropdown option on postback
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>
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于干净的方法,您可以设置 cookie
看一下以下问题和回复
jQuery cookie 设置页面刷新后选择下拉值
*但我最喜欢的是使用 ajax 方法在用户会话中设置选择。
For a clean method you can set a cookie
Take a look at the following question and the replies
jQuery cookies setting select drop down value after page refresh
*But my favorite is to set the selection in the user session using ajax method.