JS地理位置国下拉
我使用get ipapi.co/country来检测位置国家,然后根据此位置使SELECT OPTION活跃。但这使得呈现国家选项的形式有些慢。谁能建议我可以更快地做出响应?这是我正在使用的代码:
$.get("https://ipapi.co/country/", function (t) {
(clientCountry = "AU"), (clientCountry = t), $("#country option[value=" + clientCountry + "]").val(), $("#country option[value=" + clientCountry + "]").attr("selected", "selected");
var e = $("#country option:selected").attr("age");
$("#age-gate__country .ui-selectmenu-status").text($("select[name=country] option:selected").text());
var a = new Date(new Date().setFullYear(new Date().getFullYear() - e)).toLocaleDateString("en-US");
}),
I use get ipapi.co/country for detecting the location country and then to make the select option active depending on this location. But it makes the form a little bit slow to render the country option. Can anyone recommend if I can make the response faster? This is the code I'm using:
$.get("https://ipapi.co/country/", function (t) {
(clientCountry = "AU"), (clientCountry = t), $("#country option[value=" + clientCountry + "]").val(), $("#country option[value=" + clientCountry + "]").attr("selected", "selected");
var e = $("#country option:selected").attr("age");
$("#age-gate__country .ui-selectmenu-status").text($("select[name=country] option:selected").text());
var a = new Date(new Date().setFullYear(new Date().getFullYear() - e)).toLocaleDateString("en-US");
}),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码非常简单,我怀疑性能瓶颈。 API或请求可能是瓶颈,但不能修复(至少不是由您而是API提供商)。
The code is so simple that I doubt is the performance bottleneck. The API or the request may be the bottleneck but that cannot be fixed (at least not by you but only by the API provider).