Json獲取中國天氣網天氣預報的代碼
來源:程序員人生 發布時間:2013-12-06 10:40:35 閱讀次數:4622次
獲取中國天氣網天氣的代碼
var url=escape("http://m.weather.com.cn/data/101210701.html");
var cookie_info = "cookie_info";
var date = new date();
var hours=24-date.gethours()-1;
var mins=60-date.getminutes()-1;
var secs=60-date.getseconds();
date.settime(date.gettime() + (1 * hours * 60 * 60 * 1000) + (1 * 1 * mins * 60 * 1000) + (1 * 1 * 1 * secs * 1000));
var rd_cookie_info= $.cookie(cookie_info);
$(function(){
if(rd_cookie_info==null)
{
getdata(url);
}
else{
$("#weather").html(rd_cookie_info);
}
})
function getdata(url)
{
$.ajax({
type:"get",
cache: "false",
url: "ajaxget.asp教程",
data:"url="+url,
datatype: "html",
error: function(){$("#weather").html("讀取失敗...請刷新重試!");},
success: function(網頁特效on){
var t = '('+json+')';
var result = eval(t);
var getinfo="";
getinfo+=result.weatherinfo.date_y+" ";//年月日
getinfo+=result.weatherinfo.date+" ";//農歷年月日
getinfo+=result.weatherinfo.week+" ";//星期幾
getinfo+="<br />";//換行 liehuo.net
getinfo+=result.weatherinfo.city;//獲取城市名稱
getinfo+=" <img src="http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif"/> "//天氣圖片1
getinfo+="<img src="http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif"/> ";//天氣圖片2
getinfo+=result.weatherinfo.weather1+" ";//天氣情況
getinfo+=result.weatherinfo.temp1;//溫度
$.cookie(cookie_info,getinfo, { path: '/', expires: date });
$("#weather").html(getinfo);
}
});
}
<div id="weather" style="font-size:12px;"></div>
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈