【发布时间】:2012-01-05 16:08:14
【问题描述】:
我正在尝试检查 url 中是否有 hos 参数有任何内容,如果有,则将该值作为 selected 属性传递给页面刷新时的下拉菜单,因此即使在刷新后下拉选项仍保持选中状态
var value = window.location.href.match(/[?&]hos=([^&#]+)/) || [];
if (value.length == 2) {
$('#hospitalDropDown[value="' + value[1] + '"]').attr('selected', 'selected');
}
这是下拉菜单:
<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>
【问题讨论】:
-
那么 url 是什么样的,选项是什么样的?
-
你为什么不先完成这个? stackoverflow.com/questions/8743701/…
标签: javascript jquery selection dropdownbox