首页 > 解决方案 > 从选项选择中选择值后如何在js中重定向

问题描述

我是网络开发的初学者。我有这个代码:

<select class="selectpicker indexSelect10 filterMenu10  callendarFilter callendarFilterCategory" name="sortAfter">
    <option value="lang/pl">PL</option>
    <option value="lang/de">DE</option>
    <option value="lang/en">EN</option>
</select>

在值中,我有 url 地址。选择值后,我想将用户从选项值重定向到 url:domain.com/lang/en

我该怎么做?

标签: javascriptjquery

解决方案


// $(el).on("change") will listen whenever the select has new value
$("select").on("change", function(){
    // if select value changed
    var id = $(this).val() // get select value
    window.location.href = "/new/url/route?id=" + id // redirect to somewhere
})

推荐阅读