使用intl-tel-input库的自动国别功能无法使用。

问题描述 投票:2回答:1

我已经尝试从这个github源码实现国际电话输入。

https:/github.comjackocnrintl-tel-input。

我想做的是,我需要通过位置来自动选择国家.我从github源头上读到了关于自动国家这样的。

intlTelInput(input, {
  initialCountry: "auto",
  geoIpLookup: function(success, failure) {
    $.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
      var countryCode = (resp && resp.country) ? resp.country : "";
      success(countryCode);
    });
  },
});

这是我的代码。

var input1 = document.querySelector("#telephone1");
var iti1 = window.intlTelInput(input1,({        
  // options here       
    initialCountry: "auto",
    geoIpLookup: function(success, failure) {
        $.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
          var countryCode = (resp && resp.country) ? resp.country : "";
          success(countryCode);
        });
      },

}));

但我得到的是没有国家别名的空白标志,没有国家.我没有得到一个错误,只是我不能从我的位置从上面的代码得到国家。

我的代码有什么问题?

国家应该是 "AU "澳大利亚。似乎我做了一个我不明白的错误。

谢谢你

enter image description here

javascript jquery jquery-plugins
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.