在HTML下拉值的select事件中,我想触发将其定向到某个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

有人可以帮忙吗?

最佳答案

在jQuery中

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


编辑:更改为更现代的“绑定”

关于javascript - 将下拉选择的值作为查询字符串传递给URL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8659788/

10-12 00:14
查看更多