欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js获取ip和地区

程序员文章站 2024-01-20 13:19:10
这个接口是搜狐的目前是可用的, 就是不知道以后会不会失效 效果图: 代码如下: ...

这个接口是搜狐的目前是可用的, 就是不知道以后会不会失效

效果图:

js获取ip和地区

代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>t1</title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<style>
/* css reset */
body,p,ol,ul,li,dl,dd,h1,h2,h3,h4,h5,h6,input,iframe,nav,header,footer {
  margin: 0;
  padding: 0;
  list-style: none;
}
body {
  font: 16px microsoft yahei, sans-serif;
  color: #2a2b2c;
  background: #fff;
}
a,img {
  text-decoration: none;
  color: #2a2b2c;
  border: 0;
}
*, *::before, *::after {
  outline: none;
  box-sizing: border-box;
}
.xxx-btn {
  display: block;
  width: 100px;
  height: 38px;
  font: 16px/38px microsoft yahei;
  color: #fff;
  background: #0cf;
  border: 0;
  cursor: pointer;
  text-align: center;
  border-radius: 2px;
  box-shadow: 0 1px 5px #bbb;
  opacity: .8;
  transition: .5s;
}
.xxx-btn:hover {
  opacity: 1;
  box-shadow: 0 1px 10px #aaa;
}
</style>
</head>
<body>
<h1>点击获取ip</h1>
<br>
<button class="xxx-btn" onclick="aa()">click me</button>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
function aa() {
  alert(returncitysn['cip'] + returncitysn['cname']);
};
</script>
</body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!