【发布时间】:2017-08-04 12:47:43
【问题描述】:
如果访问者来自美国,我想隐藏第一个 div,如果访问者不是来自美国,我想隐藏第二个 div。两个 div 具有相同的类。
<div class="myclass">from US</div>
<div class="myclass">not from US</div>
我发现了一些使用 freegeoip.net/json 的简单实现,但我无法根据我的特定需求进行调整。
$.get("http://freegeoip.net/json/", function (response) {
$("#ip").html("IP: " + response.ip);
document.getElementsByClassName(response.country_code)[0].style.display = "none";
}, "jsonp");
【问题讨论】:
-
到目前为止您尝试过什么?添加更多示例代码
-
我尝试改编这个例子,但失败了:stackoverflow.com/questions/30173809/…