我想创建一个下拉菜单,使用英语或德语作为JavaScript / jQuery中的选项,检查:
check if on a domain - say happy.com/pizza
if german is selected on dropdown
redirect user to
happy.de/pizza
and I could have a list
if happy.com/pizza got to happy.de/pizza
happy.com/coke got to happy.de/coke
happy.com/juice got to happy.de/juice
etc etc.
我已经编写了代码但是怎么会这样呢?
我已经编写了一些代码,但我需要一点帮助:
在这种情况下,我在www.something.com/beer页面上,希望它去德国啤酒页面!
<select>
<option value="1">English</option>
<option value="2">German</option>
</select>
if(value == 2) && is current domain www.something.com/beer{
window.top.location.href = 'www.something.de/beer';
}else if(value == 2) && is current domain www.something.com/cheese{
window.top.location.href = 'www.something.de/cheese';
}else{
do nothing
}
如何检查下拉列表的值并且域当前处于开启状态?
这是我的Jsfiddle
我真的被困在了&amp;&amp;是当前部分我该怎么做?
答案 0 :(得分:2)
试试这个
if (value == 2 && location.href.indexOf('www.something.com/beer') >= 0) {
window.top.location.href = 'www.something.de/beer';
} else if (value == 2 && location.href.indexOf('www.something.com/cheese') >= 0) {
window.top.location.href = 'www.something.de/cheese';
} else {
}
location.href
- 返回当前网址,indexOf
检查当前网址中是否有您的字符串