如果访问者来自美国,我想隐藏第一个div,如果访问者不是来自美国,我想隐藏第二个div。两个div都有相同的类。jquery根据geoIP隐藏第一个或第二个子元素
<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");
你到目前为止试过的东西?添加更多的示例代码 –
我试图适应这个例子,但我失败了:https://stackoverflow.com/questions/30173809/how-to-show-or-hide-element-based-on-geo-ip –