天气预报(七)js全部代码,需者自取

<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
<script  src="http://tianqi.2345.com/js/citySelectData2.js" charset="gbk">
</script>
<script>
var a=provqx.join(".")
var len=a.indexOf(remote_ip_info.city)-8;
var citycode=a.substr(len,5);
var url=new Array();
 url[0]='http://tianqi.2345.com/t/shikuang/'+citycode+'.js';//当天天气
 url[1]='http://tianqi.2345.com/t/tqChart/'+citycode+'.js';//七天温度预报
 url[2]='http://tianqi.2345.com/t/wea_hour_js/'+citycode+'.js';//阴晴变化
var script=new Array();
var head = document.getElementsByTagName('head')[0];
for(var i=0;i<3;i++){
	script[i]= document.createElement('script'); 
	script[i].type= 'text/javascript'; 
	script[i].src=url[i];
	head.appendChild(script[i]);
	script[i].defer===true;
}
	
	var myDate = new Date();
$(document).ready(function(){
script[0].onload=function(){
	$('.city h2').html('当前定位城市:'+remote_ip_info.city);
	$('.date h2').html('当前日期是:'+myDate.getFullYear()+'年'+myDate.getMonth()+1+'月'+myDate.getDate()+'日');
	$('.humidity').html('湿度:'+weatherinfovar.weatherinfo.SD);
	$('.humidity').html('湿度:'+weatherinfovar.weatherinfo.SD);
	$('.water').html(weatherinfovar.weatherinfo.JS);
	$('.air').html('空气质量:'+weatherinfovar.weatherinfo.lv_hint);
	$('.windForce').html('风力:'+weatherinfovar.weatherinfo.WS);
	$('.windDirection').html('风向:'+weatherinfovar.weatherinfo.WD);
	$('.airPressure').html('气压:'+weatherinfovar.weatherinfo.QY+'hPa');
}
script[1].onload=function(){
	$('.temperature').html(data[1].wenduH+'°C~'+data[1].wenduB+'°C');
	$('.gai').each(function(index){//日期计算,并没有考虑闰年,多半是因为懒
	if(myDate.getMonth()!==1){//index是从0开始的,所以要index+1看到明天。'<br />'为啥一定要有个引号呢?
		if((!dateaccount()&&myDate.getDate()+index+1<32)||(dateaccount()&&myDate.getDate()+index+1<31))
			$('.gai').eq(index).html(myDate.getDate()+index+1+'日'+ '<br />'+data[index+2].wenduH+'°C~'+data[index+2].wenduB+'°C');
		if(!dateaccount()&&myDate.getDate()+index+1>31)
			$('.gai').eq(index).html(myDate.getDate()+index+1-31+'日'+ '<br />'+data[index+2].wenduH+'°C~'+data[index+2].wenduB+'°C');
		if(dateaccount()&&myDate.getDate()+index+1>30)
			$('.gai').eq(index).html(myDate.getDate()+index+1-30+'日'+ '<br />'+data[index+2].wenduH+'°C~'+data[index+2].wenduB+'°C');
	}
	else{
		if(myDate.getDate()+index+1<29)
			$('.gai').eq(index).html(myDate.getDate()+index+1+'日'+ '<br />'+data[index+2].wenduH+'°C~'+data[index+2].wenduB+'°C');
		else
			$('.gai').eq(index).html(myDate.getDate()+index+1-28+'日'+ '<br />'+data[index+2].wenduH+'°C~'+data[index+2].wenduB+'°C');
	}
	})
}
script[2].onload=function(){
	if((wea_h_hour[8].tq)===(wea_h_hour[14].tq))
		$('.weather').html(wea_h_hour[9].tq);
	else
		$('.weather').html(wea_h_hour[9].tq+'转'+wea_h_hour[14].tq);
}
});
function dateaccount(){//这个月有几天
	var day31=[0,2,4,6,7,9,11]
	for(i=0;i<day31.length;i++){
		if(myDate.getMonth()===day31[i])
			return false;
	}
	return true;
}
//console.log(weatherinfovar)
</script> 
关于天气的全部代码请访问:https://codepen.io/55juekun/pen/mpKKgz

猜你喜欢

转载自blog.csdn.net/u013051947/article/details/79055761