【发布时间】:2012-01-06 00:00:46
【问题描述】:
<asp:DropDownList runat="server" id="DropDownList1"
DataSourceID="spdatasource1" DataValueField="CategoryName"
AutoPostBack="false">
</asp:DropDownList>
这个 asp.net dropdonwlist 控件呈现以下 html。它被数据绑定到一个共享点列表。下拉选项正在动态填充。我正在尝试操纵一个选项的 onselect 以重定向到这样的某个链接:它确实被重定向到该站点,但它始终传递第一个选项值。如果我选择 Cancer,它仍然是 http://somesite/events/Pages/default1.aspx?cat=Select Category.. 为什么??
<select name="ctl00$PlaceHolderMain$ctl00$DropDownList1" id="ctl00_PlaceHolderMain_ctl00_DropDownList1">
<option value="Select Category">Select Category</option>
<option value="All Categories">All Categories</option>
<option value="Cancer">Cancer</option>
<option value="Health Lecture">Health Lecture</option>
<option value="Heart Health">Heart Health</option>
</select>
jquery用来抓取选项并传递给url:
var selectedOption = $("#ctl00_PlaceHolderMain_ctl00_DropDownList1 option:selected").val();
$("#ctl00_PlaceHolderMain_ctl00_DropDownList1").change(function(e) {
window.location.href = 'http://somesite/events/Pages/default1.aspx?cat=' + selectedOption
});
【问题讨论】:
标签: jquery redirect drop-down-menu onchange