Anj*_*apa 1 javascript jquery onchange drop-down-menu
是否有可能使下拉列表选择触发器返回到同一页面,其中使用javascript将所选内容添加到URL作为查询字符串?问题是列表是从某个共享点列表动态加载的.如果我的网站是mysite.com/default.aspx所以当做出选择时,它应该重定向到mysite.com/default.aspx?key=selection
没有服务器访问,无法访问codebehind :(
<asp:DropDownList runat="server" id="DropDownList1" DataSourceID="spdatasource1" DataValueField="CategoryName" AutoPostBack="True" Onchange="window.open( Go to some link)">
</asp:DropDownList>
Run Code Online (Sandbox Code Playgroud)
var selectedOption = $("#DropDownList1 option:selected").text();
$("#DropDownList1").change(function(e) {
url: "mysite.com/default.aspx?key=" + selectedOption;
window.location = url;
});
Run Code Online (Sandbox Code Playgroud)
未经测试,也不确定重新加载页面的事件,例如(提交或锚定)
另一种选择(可能更好)来自http://tinyurl.com/82ter35
$(document).ready(function() {
var selectedOption = $("#DropDownList1 option:selected").text();
$("#DropDownList1").change(function() {
$.ajax({
type: "POST",
url: "mysite.com/default.aspx?key=" + selectedOption,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
alert("this worked!");
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26300 次 |
| 最近记录: |