<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取IP地址</title>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<body>
<div style="width: 240px;height: 320px;border: 1px solid #ccc;border-radius: 5px;padding: 20px; margin: 200px auto;">
地址:<input type="text" id="ip" name="ip"><br/>
城市:<input type="text" id="cname" name="cname"><br/>
</div>
<script>
//声明
var ip = returnCitySN["cip"];
var cname = returnCitySN["cname"];
//获取
document.getElementById("ip").value = ip;
document.getElementById("cname").value = cname;
</script>
</body>
</html>
JS获取本地ip的方法
点赞
收藏