JS获取新浪天气 在要获取新浪天气的面页加入以下代码: <script src="http://code./jquery-1.8.3.min.js" type="text/javascript"></script> <script src="tianqi.js" type="text/javascript"></script> <div id="tianqi"></div> //显示天气 以下为tianqi.js代码: var weather=function(){ var tmp=0; var SWther={w:[{}],add:{}}; var SWther={}; this.getWeather=function(type){ $.getScript("http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city="+citytq+"&day=0&dfc=3",function(){if(type=='js'){echo();}}) ;} function echo(){ $('.tianqi').html(citytq+"温度:"+window.SWther.w[citytq][0].t1+"℃~"+window.SWther.w[citytq][0].t2+"℃ 天气:"+window.SWther.w[citytq][0].s1+"~"+window.SWther.w[citytq][0].s2); } } function jintian(){ weather_.getWeather('js'); }; var weather_=new weather(); $(document).ready(function(){ $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js',function(){ citytq=remote_ip_info.city //获取城市 jintian(); }) }); |
|