下面這段JS代碼是通過jquery 結合新浪IP地址庫和QQip地址庫接口獲取用戶當前所在的城市(省份)名稱、 用戶當前IP地址等數據。其中當前IP是通過 QQip地址庫接口獲取,其他數據都是通過 新浪IP地址庫接口獲取。因為 QQip地址庫速度較慢,所以IP地址經常會無法顯示出來,要多刷新幾次。獲取到的這些數據具體作用可以結合自己的網站所需功能來用,本人主要是想通過獲取到當前城市名稱來調用新浪天氣預報的當前城市天氣預報信息,如:《jquery 天氣預報代碼》
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MJBlog(mj.588cy.com)</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //通過調用新浪IP地址庫接口查詢用戶當前所在國家、省份、城市、運營商信息 $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js',function(){ $(".country").html(remote_ip_info.country); $(".province").html(remote_ip_info.province); $(".city").html(remote_ip_info.city); $(".isp").html(remote_ip_info.isp); }); //通過調用QQIP地址庫接口查詢本機當前的IP地址 $.getScript('http://fw.qq.com/ipaddress',function(){ $(".ip").html(IPData[0]); }); }); </script> </head> <body> <div>國家:<span class="country"></span></div> <div>省份:<span class="province"></span></div> <div>城市:<span class="city"></span></div> <div>IP地址:<span class="ip"></span></div> <div>運營商:<span class="isp"></span></div> </body> </html>
轉自http://mj.588cy.com/jquery/10.html