我有这个脚本给我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)