js实现PC端根据IP定位当前城市地理位置

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
// document.write(JSON.stringify(returnCitySN));
var cname = JSON.stringify(returnCitySN.cname);
var province = '';
if(cname.indexOf('省')!=-1){
var province = cname.substring(1,cname.indexOf('省')+1);
}else if(cname.indexOf('区')!=-1){
province = cname.substring(1,cname.indexOf('区')+1);
}
var city = cname.substring(cname.indexOf('省')+1,cname.length-1);
document.write('省:'+province+','+'市:'+city);
</script>


原文链接:https://blog.csdn.net/cuilei210/java/article/details/78789880

posted @ 2020-05-20 15:36  Mr.渣、  阅读(971)  评论(0编辑  收藏  举报