⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _weather.js

📁 具有的功能适合于网站的运营和管理
💻 JS
字号:
// JavaScript Document
/*定义建立XMLHttpRequest的函数---------------------------------------------------------------开始*/
function CreateXMLHttpRequest()
{
xmlhttp=false;
if(window.XMLHttpRequest)//Mozilla,Sofari
    {xmlhttp=new XMLHttpRequest();
      if (xmlhttp.overrideMimeType)
       {xmlhttp.overrideMimeType('text/xml');}
    }
    else if(window.ActiveXObject)//IE
        {
            try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
            catch(e){
                try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
                catch(e){}
                }
            }
}            
/*定义建立XMLHttpRequest的函数---------------------------------------------------------------结束*/

function loadPage()
{
    loadCity();
    }
    
function loadWeather(city)
{
    CreateXMLHttpRequest();
    if(!xmlhttp)
    {
        document.getElementById("weatherinfo").innerHTML="对不起,服务器有故障,不能传送数据!";
        return false;
        }
        else
            {
                xmlhttp.onreadystatechange=loadWeatherInfo;
                URL="weather.aspx?city="+city;              
                xmlhttp.open("post",URL,true);
                xmlhttp.send(null);
                }
}

function loadWeatherInfo()                
{
    if(xmlhttp.readyState==4)
    {
        if(xmlhttp.status==200)
        {
            var weathers=xmlhttp.responseText;
            var weather=weathers.split(",");
            var weatherInfo="";
            var marks=new Array("城市","日期","天气","温度","风力");
			var s = getWeatherShow(weather[2])+'<br>'
            for(i=0;i<weather.length;i++)
            {   
			    ;
                weatherInfo+=marks[i]+":"+weather[i]+"<br>";
            }
                document.getElementById("weatherinfo").innerHTML=weatherInfo+s;
        }
    }
    else
    {
     document.getElementById("weatherinfo").innerHTML="<table><tr><td><img src='images/loading.gif' /></td><td> 数据装载ing...</td></tr></table>";        
    }
}    

function loadCity()
{
    CreateXMLHttpRequest();
    if(!xmlhttp)
    {
        document.getElementById("weatherinfo").innerHTML="对不起,服务器有故障,不能传送数据!";
        return false;
        }
        else
            {
                xmlhttp.onreadystatechange=loadCityInfo;
                URL="http://192.168.1.5/weather/city_ajax_list.asp";
                xmlhttp.open("get",URL,true);
                xmlhttp.send(null);
                }    
    }
    
function loadCityInfo()                
{
        if(xmlhttp.readyState==4)
    {
        if(xmlhttp.status==200)
        {
            var citys=xmlhttp.responseText;
            var city=citys.split(",");
            var cityInfo="请选择城市:<select id='cityselect' value='上海' onchange='loadWeather(this.value)'>"
            for(i=0;i<city.length;i++)
            {
                cityInfo+="<option value="+escape(city[i])+">"+city[i]+"</option>";
                }    
                cityInfo+="</select>";
                document.getElementById("cityinfo").innerHTML= cityInfo;
                loadWeather(escape("上海"));
                }
        }
            else
            {
                document.getElementById("cityinfo").innerHTML="<table><tr><td><img src='images/loading.gif' /></td><td> 数据装载ing...</td></tr></table>";        
                }
} 
function getWeatherShow(s){//获取天气的名称如'阵雨'
		var a = s.split("转");
	    s = "";
		for(var i=0;i<a.length;i++){
			s += getWeatherIcon(a[i]);//获取对应天气的图标
		}
		return s;
	}
	function getWeatherIcon(s){
		var icons = new Array();
		icons[0]	= {name:"",src:"w0.gif"};
		icons[1]	= {name:"中雨",src:"w1.gif"}; 
		icons[2]	= {name:"中雪",src:"w2.gif"}; 
		icons[3]	= {name:"暴雨",src:"w3.gif"}; 
		icons[4]	= {name:"多云",src:"w4.gif"}; 
		icons[5]	= {name:"小雨",src:"w5.gif"}; 
		icons[6]	= {name:"大雨",src:"w6.gif"}; 
		icons[7]	= {name:"阴",src:"w7.gif"}; 
		icons[8]	= {name:"晴",src:"w8.gif"}; 
		icons[9]	= {name:"雾",src:"w9.gif"}; 
		icons[10]	= {name:"雨加雪",src:"w10.gif"}; 
		icons[11]	= {name:"扬沙",src:"w11.gif"}; 
		icons[12]	= {name:"冰雹",src:"w12.gif"}; 
		icons[13]	= {name:"小雪",src:"w13.gif"}; 
		icons[14]	= {name:"雷阵雨",src:"w14.gif"}; 
		icons[15]	= {name:"大雪",src:"w15.gif"}; 
		icons[16]	= {name:"阵雨",src:"w16.gif"}; 
		var r = icons[0].src;
		for(var i=1;i<icons.length;i++){
			if(icons[i].name == s){
				r = icons[i].src;
				break;
			}
		}
		return '<img src="icons/'+r+'" width="60" height="60" border="0" align="absmiddle">';
	}   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -