javascript - 从选项选择中选择值后如何在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
我该怎么做?
解决方案
// $(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
})
推荐阅读
- sql - 是否可以创建 Azure SQL 数据库主主复制
- python - 在列表中查找总和为目标数字的一对数字
- java - 有没有办法在 android 中刷新 SQLite 数据库文件中的更改?
- java - Eclipse:如何从 Eclipse 配置创建独立服务器
- java - 如何使用 Gradle 命令行参数更改代码变量
- mysql - MySql Count 子句与 where
- arrays - Perl - 从存储在哈希引用中的数组中获取数组值的问题
- c++ - 获取两个不同模板的产品类型
- php - 如何在php中使用htaccess重定向到特定的文件夹/页面
- animation - Update normals of animated skinned mesh in three.js?