刷新时保留下拉选择

发布于 2024-12-24 18:54:10 字数 815 浏览 6 评论 0原文

可能的重复:
在回发时保留选定的下拉选项

当用户选择该选项时,我有一个下拉菜单,该值将传递到与刷新页面的查询字符串相同的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以歌曲疗慰 2024-12-31 18:54:10

对于干净的方法,您可以设置 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.

请持续率性 2024-12-31 18:54:10
<select id="hospitalDropDown"> 
    <option value="">All Hospitals</option>
    <option value="Dyer">Dyer</option>
    <option value="Carmel">Carmel</option>
</select>
<script type="text/javascript">

$(document).ready(function() {
    $('#hospitalDropDown').val('<?php echo $_GET['hos']; ?>');
    $('#hospitalDropDown').change(function() {
        location.href = 'http://mysite.com/events/Pages/default1.aspx?hos=' + $(this).val();
    });
});
</script>
<select id="hospitalDropDown"> 
    <option value="">All Hospitals</option>
    <option value="Dyer">Dyer</option>
    <option value="Carmel">Carmel</option>
</select>
<script type="text/javascript">

$(document).ready(function() {
    $('#hospitalDropDown').val('<?php echo $_GET['hos']; ?>');
    $('#hospitalDropDown').change(function() {
        location.href = 'http://mysite.com/events/Pages/default1.aspx?hos=' + $(this).val();
    });
});
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文