#result{width: 800px;border:1px solid #ddd;margin-top: 30px;background: #aaa;display: none;}
#result p{height: 25px;line-height: 25px;padding-left: 20px;color: #fff;font-weight: bold;font-size: 16px;}
#result p span{padding: 0 10px;display: inline-block;width: 120px;text-align:center;height: 25px;line-height: 25px;}
#result p span.temp{width: 250px;text-align: left;margin-left: 20px;}
$(function(){
$(window).on('load',function(){
$.ajax({
'type':'get',
'url':'http://apis.baidu.com/heweather/weather/free?city=beijing',
'headers':{'apikey':'2c6d2927ef76200697018e989f6afbbb'},
'success':function(data){
$('#result').show();
data = data['HeWeather data service 3.0'][0];
var basic_info = '城市:' + data.basic.cnty + ' ' + data.basic.city;
var tianqi = data.daily_forecast;
$('
' + basic_info + '
').appendTo('#result');$('
日期氣溫天氣
').appendTo('#result');$.each(tianqi,function(index,element){
var html = '';
var date = element.date;
var temperature = element.tmp.min + '°C - ' + element.tmp.max + '°C';
var w1 = element.cond.txt_d;
var w2 = element.cond.txt_n;
var weather;
if(w1 == w2){
weather = w1;
}
else{
weather = w1 + ' 轉(zhuǎn) ' + w2;
}
html += ''+ date +'' + ''+ temperature +'' + ''+ weather +'';
$('
'+ html +'
').appendTo('#result');});
}
});
});
$('#query').on('click',function(){
$('#result').hide().empty();
var city = $.trim($('#city').val());
$.ajax({
'type':'get',
'url':'http://apis.baidu.com/heweather/weather/free',
'data':{'city':city},
'headers':{'apikey':'2c6d2927ef76200697018e989f6afbbb'},
'success':function(data){
$('#city').val('');
data = data['HeWeather data service 3.0'][0];
console.log(data);
var basic_info = '城市:' + data.basic.cnty + ' ' + data.basic.city;
var tianqi = data.daily_forecast;
$('
' + basic_info + '
').appendTo('#result');$('
日期氣溫天氣
').appendTo('#result');$.each(tianqi,function(index,element){
var html = '';
var date = element.date;
var temperature = element.tmp.min + '℃ - ' + element.tmp.max + '℃';
var w1 = element.cond.txt_d;
var w2 = element.cond.txt_n;
var weather;
if(w1 == w2){
weather = w1;
}
else{
weather = w1 + ' 轉(zhuǎn) ' + w2;
}
html += ''+ date +'' + ''+ temperature +'' + ''+ weather +'';
$('
'+ html +'
').appendTo('#result');$('#result').show();
});
}
});
});
});
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。