jquery javascript onchange event to www.example.com 下拉列表

zbdgwd5y  于 2023-04-29  发布在  jQuery
关注(0)|答案(2)|浏览(115)

有没有可能使下拉列表选择触发器回发到同一个页面上,并使用javascript将所选内容添加到url中作为querystring?问题是列表是从某个sharepoint列表动态加载的。如果我的网站是www.example www.example.com ,因此当做出选择时,它应该重定向到 www.example.com
没有服务器访问,没有访问代码隐藏:(

<asp:DropDownList runat="server" id="DropDownList1" DataSourceID="spdatasource1" DataValueField="CategoryName" AutoPostBack="True" Onchange="window.open( Go to some link)">
                                                 </asp:DropDownList>
9gm1akwq

9gm1akwq1#

var selectedOption = $("#DropDownList1 option:selected").text();

$("#DropDownList1").change(function(e) {
      url: "mysite.com/default.aspx?key=" + selectedOption;
      window.location = url;
});

未测试,也不确定是什么事件重新加载页面e。g.(提交或锚)
here的另一个选项(可能更好)

$(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!");
      }
    });
  });
});
z18hc3ub

z18hc3ub2#

我不确定你想做什么,但我猜jquery是你问题的正确答案
无论如何,这可能会有所帮助:

<script language="javascript" type="text/javascript">
    function xx(e) {
        alert("fired by " + "<%= DropDownList1.UniqueID %>" + "change ");
        __doPostBack("<%= DropDownList1.UniqueID %>", "");
    }
</script>

<asp:DropDownList ID="DropDownList1" runat="server" onchange="xx()">
    <asp:ListItem>q</asp:ListItem>
    <asp:ListItem>w</asp:ListItem>
    <asp:ListItem>e</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList>

代码隐藏(VB.NET)

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    MsgBox("Do whatever you want here")
End Sub

相关问题