检查数组中的值

时间:2015-03-06 14:05:19

标签: javascript jquery

我需要检查当前位置是否在欧洲,如果是,请执行一些代码。由于没有伞形“欧盟”代码,我必须列出国家并将它们存储在一个数组中。我无法找出检查阵列的最佳方法......

jQuery.ajax( { 
  url: '//freegeoip.net/json/', 
  type: 'POST', 
  dataType: 'jsonp',
  success: function(location) {
    // If the visitor is browsing from UK.
    if (location.country_code === 'GB') {
      // do UK thing
    }
    // If the visitor is browsing from US.
    else if(location.country_code === 'US'){
      // do US thing
    }
    else if(location.country_code === EU){
      //do EU thing
    }
    else{
      // do nothing
    }
  }
} );


var EU = ["AT", "BE", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GR", "HU", "IE", "NO", "NL", "PO", "SE"];

0 个答案:

没有答案