简体   繁体   English

将下拉选择的值作为查询字符串传递给URL

[英]Passing dropdown selected value as query string to URL

On select event of a HTML dropdown value, I want to trigger being directed to a certain URL and that selected value being appended to the URL as query string. 在HTML下拉值的select事件中,我想触发被定向到某个URL,然后将该选定值作为查询字符串附加到URL。 How to achieve that in javascript or jquery? 如何在javascript或jquery中实现呢?

<select id="hospitalDropDown">
            <option>All Hospitals</option>
            <option>Dyer</option>
        <option>Carmel</option>
        <option>Indianapolis</option>
        <option>Beech Grove</option>
</select> 

So if Dyer is selected, the result should be being directed to http://mysite.com/events.aspx?hosp=Dyer 因此,如果选择了Dyer,则应将结果定向到http://mysite.com/events.aspx?hosp=Dyer

Can someone help? 有人可以帮忙吗?

in jquery 在jQuery中

$( '#hospitalDropDown' ).on( 'change', function( e ){
  document.location.href = "http://blah" + $( this ).val();
});

EDIT: changed "bind" to the more modern "on" 编辑:更改为更现代的“绑定”

If you're using the latest version of jQuery, you can attach an event handler using the on() function . 如果您使用的是最新版本的jQuery,则可以使用on()函数附加事件处理程序。

$('#hospitalDropDown').on('change', function () {
    window.location.assign('http://mysite.com/events.aspx?hosp=' + $(this).val());
});

To see this in action: http://jsfiddle.net/73PEg/ 要查看实际效果: http : //jsfiddle.net/73PEg/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将所选的下拉值传递到锚标记中的查询字符串 - Passing selected dropdown value to query string in an anchor tag 将DropDown选择的值与其他选择的查询结果集一起传递 - Passing DropDown selected value along with other selected query result set 将下拉选择的值传递给javascript中的锚标签打开窗口的URL - passing dropdown selected value to URL in javascript for an anchor tag opening window 如何将选定的下拉列值传递到同一jsp页面上的url查询字符串 - How to pass selected dropdown value to url query string on the same jsp page 将选定的下拉字符串值从表中传递给控制器 - Passing selected dropdown string value from table in view to controller 在URL中传递下拉列表的选定值 - Passing selected value of dropdownlist in URL 在反应中将下拉列表的选定值传递给 API - Passing selected value of Dropdown into API in react 在JavaScript / AJAX中传递带有查询字符串中的值的代码并附加到URL - Passing code with a value in a query string appended to the URL in JavaScript/AJAX React Native Element Dropdown,将下拉选择的值传递给父组件 - React Native Element Dropdown, Passing Dropdown selected value to parent component 如果 URL 与值匹配,如何选择下拉列表? - How to make dropdown selected if URL matched with value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM