小编Gro*_*roc的帖子

如何根据Geo ip显示或隐藏元素

我有这个脚本给我Geo位置,比如"CA"或"US".我想在我的html基础上显示一个特定的用户位置.有什么建议?

HTML:

<div id="ip">Loading...</div>
<div id="country_code"></div>
<div id="country_code">Hello Canada</div>
<div id="country_code">Hello USA</div>


<script>
    $.get("https://freegeoip.net/json/", function (response) {
        $("#ip").html("IP: " + response.ip);
        $("#country_code").html(response.country_code);
    }, "jsonp");
    document.getElementById("US").style.display = "block";
    document.getElementById("CA").style.display = "block";
</script>
Run Code Online (Sandbox Code Playgroud)

CSS:

#US { text-align: left; color: blue; display:none;} 
#CA { text-align: left; color: blue; display:none;} 
Run Code Online (Sandbox Code Playgroud)

的jsfiddle

html javascript css jquery

0
推荐指数
1
解决办法
4552
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1