首页 > Web开发 > 详细

js根据ip地址获取所在城市

时间:2015-01-10 18:18:58      阅读:631      评论:0      收藏:0      [点我收藏+]


话不多说,直接贴代码!
将这段代码运行一下就OK了:
<html xmlns="">
<head runat="server">
   <title>根据IP地址获取所在城市</title>
   <scriptsrc="?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>


所用接口: 
?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:所用网络(例如电信)

js根据ip地址获取所在城市

原文:http://blog.csdn.net/s592652578/article/details/42583153

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!