0
<asp:DropDownList runat="server" id="DropDownList1"
DataSourceID="spdatasource1" DataValueField="CategoryName"
AutoPostBack="false">
</asp:DropDownList>
這個asp.net dropdonwlist控件呈現下面的html。它是數據綁定到分享點列表。下拉選項正在被動態填充。我試圖操縱選擇一個選項重定向到這樣的鏈接:它會重定向到站點,但它總是傳遞第一個選項值。如果我選擇巨蟹座,它仍然是http://somesite/events/Pages/default1.aspx?cat=Select類別..爲什麼?asp.net dropdownlist onchange使用jquery渲染html
<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
});
看到它的行動:http://jsfiddle.net/ydcgX/ – 2012-01-06 01:53:34