js獲取ip和地區(qū)
更新時間:2017年03月10日 08:42:53 作者:qq2020
本文主要介紹了js獲取ip和地區(qū)的方法,具有很好的參考價值。下面跟著小編一起來看下吧
這個接口是搜狐的目前是可用的, 就是不知道以后會不會失效
效果圖:
代碼如下:
<!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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
String.prototype實現(xiàn)的一些javascript函數(shù)介紹
這篇文章主要是對String.prototype實現(xiàn)的一些javascript函數(shù)進行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11用表格輸出1-1000之間的數(shù)字實現(xiàn)代碼(附特效)
本文將介紹下用表格輸出1-1000之間的數(shù)字同時附有特效,感興趣的朋友可以參考下哈,希望對你有所幫助2013-04-04javascript解析json格式的數(shù)據(jù)方法詳解
這篇文章主要介紹了javascript解析json格式的數(shù)據(jù)方法詳解,文章通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08layui禁用側(cè)邊導(dǎo)航欄點擊事件的解決方法
今天小編就為大家分享一篇layui禁用側(cè)邊導(dǎo)航欄點擊事件的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09