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

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

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

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

9gm1akwq1#

  1. var selectedOption = $("#DropDownList1 option:selected").text();
  2. $("#DropDownList1").change(function(e) {
  3. url: "mysite.com/default.aspx?key=" + selectedOption;
  4. window.location = url;
  5. });

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

  1. $(document).ready(function() {
  2. var selectedOption = $("#DropDownList1 option:selected").text();
  3. $("#DropDownList1").change(function() {
  4. $.ajax({
  5. type: "POST",
  6. url: "mysite.com/default.aspx?key=" + selectedOption,
  7. data: "{}",
  8. contentType: "application/json; charset=utf-8",
  9. dataType: "json",
  10. success: function(msg) {
  11. // Replace the div's content with the page method's return.
  12. alert("this worked!");
  13. }
  14. });
  15. });
  16. });
展开查看全部
z18hc3ub

z18hc3ub2#

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

  1. <script language="javascript" type="text/javascript">
  2. function xx(e) {
  3. alert("fired by " + "<%= DropDownList1.UniqueID %>" + "change ");
  4. __doPostBack("<%= DropDownList1.UniqueID %>", "");
  5. }
  6. </script>
  7. <asp:DropDownList ID="DropDownList1" runat="server" onchange="xx()">
  8. <asp:ListItem>q</asp:ListItem>
  9. <asp:ListItem>w</asp:ListItem>
  10. <asp:ListItem>e</asp:ListItem>
  11. <asp:ListItem></asp:ListItem>
  12. </asp:DropDownList>

代码隐藏(VB.NET)

  1. Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
  2. MsgBox("Do whatever you want here")
  3. End Sub
展开查看全部

相关问题