<!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" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"> body{font-size:20px;text-align:center} #foo{ color:red; } </style> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script> <script src="https://ipip.yy.com/get_ip_info.php"></script> <script type="text/javascript"> $(document).ready(function(e) { var city=returnInfo.city||returnInfo.province||"國產"; var content= $("body").html().replace(/\{city\}/gi,city); $("body").html(content) }); </script> <script> </script> <title>飛鳥制作,必屬精品</title> </head> <body> <div id="foo">飛鳥在{city},你也在{city}吧?真是緣分呀!<br/>這個熱心的二貨,自己都還沒把網站弄好,就分享了{city}競價前沿代碼喲!</div> </body>
直接在頁面上插入 {city} 標簽,即可替換成訪客的所屬城市。(借用的是YY的Ip池)
另外,再備注一個淘寶IP地址庫的鏈接:http://ip.taobao.com/index.php,淘寶Ip地址庫(http://ip.taobao.com//service/getIpInfo.php?ip=112.230.227.77)輸出json格式,可以用來輸出任意網站的國家 、省(自治區或直轄市)、市(縣)、運營商