Javascript 刷新时保留下拉选择

Javascript 刷新时保留下拉选择,javascript,jquery,drop-down-menu,refresh,selectedindex,Javascript,Jquery,Drop Down Menu,Refresh,Selectedindex,可能重复: 我有一个下拉列表,当用户选择该选项时,该值将传递到与querystring刷新页面相同的url。页面刷新后,我想保留所选值,以便用户知道所选内容。在jquery中如何实现这一点 <select id="hospitalDropDown" onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="http://mysite.com/ev

可能重复:

我有一个下拉列表,当用户选择该选项时,该值将传递到与querystring刷新页面相同的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>

所有医院
戴尔
卡梅尔
基本上,逻辑是将选择捕获到某个变量中,并将其传递为selected等于true,但我无法在jquery中执行此操作。我没有访问服务器端代码的权限。或者
<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>
所有医院 戴尔 卡梅尔 $(文档).ready(函数(){ $('hospitalDropDown').val(''); $(“#hospitalDropDown”).change(function(){ location.href=http://mysite.com/events/Pages/default1.aspx?hos='+$(this.val(); }); });
对于干净的方法,您可以设置cookie

请看下面的问题和回答

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