您的位置:首页 > Web前端 > JavaScript

js通过IP地址获取所在城市

2015-01-10 15:17 447 查看
话不多说,直接贴代码!

将这段代码运行一下就OK了:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

<script src="js/jquery-1.8.1.js" type="text/javascript"></script>

<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" type="text/ecmascript"></script>

<script type="text/javascript">

function getIpPlace() {

alert(remote_ip_info["province"] + "省" + ',' + remote_ip_info["city"] + "市")

} </script>

</head>

<body>

<form id="form1" runat="server">

<div>

<input id="Button1" type="button" value="根据IP地址获取所在城市" onclick="getIpPlace();" />

</div>

</form>

</body>

</html>

所用接口:
http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
返回结果:

var remote_ip_info = {"ret":1,"start":"1.192.0.0","end":"1.193.127.255","country":"\u4e2d\u56fd","province":"\u6cb3\u5357","city":"\u90d1\u5dde",

"district":"","isp":"\u7535\u4fe1","type":"","desc":""};

country:国家

province:省份

city:城市

isp:所用网络(例如电信)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: