JS地理位置国下拉

发布于 2025-02-03 05:28:58 字数 675 浏览 2 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-02-10 05:28:58

代码非常简单,我怀疑性能瓶颈。 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文