Jquery获取当前城市的天气信息
本文实例为大家分享了Jquery获取当前城市的天气信息代码,供大家参考,具体内容如下
HTML代码:
<divid="weather"></div>
Jquery代码:
functionfindWeather(){
varcityUrl='http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
$.getScript(cityUrl,function(script,textStatus,jqXHR){
varcitytq=remote_ip_info.city;//获取城市
varurl="http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city="+citytq+"&day=0&dfc=3";
$.ajax({
url:url,
dataType:"script",
scriptCharset:"gbk",
success:function(data){
var_w=window.SWther.w[citytq][0];
var_f=_w.f1+"_0.png";
if(newDate().getHours()>17){
_f=_w.f2+"_1.png";
}
varimg="<imgwidth='16px'height='16px'src='http://i2.sinaimg.cn/dy/main/weather/weatherplugin/wthIco/20_20/"+_f
+"'/>";
vartq=citytq+""+img+""+_w.s1+""+_w.t1+"℃~"+_w.t2+"℃"+_w.d1+_w.p1+"级";
$('#weather').html(tq);
}
});
});
}
findWeather();
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。