Jquery获取当前城市的天气信息

这篇文章主要为大家详细介绍了Jquery获取当前城市的天气信息,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Jquery获取当前城市的天气信息代码,供大家参考,具体内容如下

HTML代码:


Jquery代码:

 function findWeather() { var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js'; $.getScript(cityUrl, function(script, textStatus, jqXHR) { var citytq = remote_ip_info.city ;// 获取城市 var url = "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-600"; if(new Date().getHours() > 17){ _f= _w.f2+"_1.png-600"; } var img = ""; var tq = citytq + " " + img + " " + _w.s1 + " " + _w.t1 + "℃~" + _w.t2 + "℃ " + _w.d1 + _w.p1 + "级"; $('#weather').html(tq); } }); }); } findWeather();

以上就是Jquery获取当前城市的天气信息的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程