将下拉选择的值作为查询字符串传递给 URL
在 HTML 下拉值的选择事件中,我想触发定向到某个 URL 并将所选值作为查询字符串附加到 URL 的操作。如何在 javascript 或 jquery 中实现这一点?
<select id="hospitalDropDown">
<option>All Hospitals</option>
<option>Dyer</option>
<option>Carmel</option>
<option>Indianapolis</option>
<option>Beech Grove</option>
</select>
因此,如果选择 Dyer,结果应定向到 http://mysite.com/events。 aspx?hosp=Dyer
有人可以帮忙吗?
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. How to achieve that in javascript or 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
Can someone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 jquery
编辑:将“bind”更改为更现代的“on”
in jquery
EDIT: changed "bind" to the more modern "on"
如果您使用的是最新版本的 jQuery,则可以使用 on() 函数。
要查看实际效果:http://jsfiddle.net/73PEg/
If you're using the latest version of jQuery, you can attach an event handler using the on() function.
To see this in action: http://jsfiddle.net/73PEg/