用于不同语言的域切换器按钮

时间:2015-04-16 09:50:15

标签: if-statement menu

我想创建一个下拉菜单,使用英语或德语作为Javascript / jQuery中的选项,检查:

check if on a domain  - say happy.com/pizza 
if german is selected on dropdown 
redirect user to 
happy.de/pizza

我可以有一个清单

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

等等。

我已经编写了代码但是怎么会这样呢?

谢谢!

我已经编写了一些代码,但我需要一点帮助:

在这种情况下,我在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

http://jsfiddle.net/msasz2an/

再次感谢!

1 个答案:

答案 0 :(得分:1)

function current(arr) {
  //  discuss at: http://phpjs.org/functions/current/
  // original by: Brett Zamir (http://brett-zamir.me)
  //        note: Uses global: php_js to store the array pointer
  //   example 1: transport = ['foot', 'bike', 'car', 'plane'];
  //   example 1: current(transport);
  //   returns 1: 'foot'

  this.php_js = this.php_js || {};
  this.php_js.pointers = this.php_js.pointers || [];
  var indexOf = function (value) {
    for (var i = 0, length = this.length; i < length; i++) {
      if (this[i] === value) {
        return i;
      }
    }
    return -1;
  };
  // END REDUNDANT
  var pointers = this.php_js.pointers;
  if (!pointers.indexOf) {
    pointers.indexOf = indexOf;
  }
  if (pointers.indexOf(arr) === -1) {
    pointers.push(arr, 0);
  }
  var arrpos = pointers.indexOf(arr);
  var cursor = pointers[arrpos + 1];
  if (Object.prototype.toString.call(arr) === '[object Array]') {
    return arr[cursor] || false;
  }
  var ct = 0;
  for (var k in arr) {
    if (ct === cursor) {
      return arr[k];
    }
    ct++;
  }
  // Empty
  return false;
}