<HTML>
<HEAD>
<TITLE>天氣預(yù)報</TITLE>
<script language="javascript">
var xmlhttp;
function getWeather()
{
//創(chuàng)建異步對象
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
//加載服務(wù)器-注意URL參數(shù)的使用
xmlhttp.Open("GET","http://tw.weather.yahoo.com/world_single.html?city=10101",false)
//異步對象事件掛鉤
xmlhttp.onreadystatechange=stateChange;
//發(fā)送請求-無參數(shù)
xmlhttp.Send(null);
}
function stateChange()
{
if(xmlhttp.readystate==4 && xmlhttp.status==200)
{
//獲取所有返回的數(shù)據(jù)
var data=xmlhttp.responseText;
//過濾自己需要的數(shù)據(jù)
var begin=data.indexOf("國際各別都市 start");
var end=data.indexOf("國際各別都市 end");
var weather=data.substring(begin+15,end);
//填充天氣內(nèi)容
document.getElementById("divweather").innerHTML=weather;
//顯示結(jié)果
document.getElementById("divweather").style.visibility="visible";
}
}
</script>
</HEAD>
<BODY onLoad="getWeather()">
<div align="center" id="today_time">今天的日期
</div>
<div align="center" id="divweather"></div>
<script language="javascript">
//設(shè)置顯示星期幾-用數(shù)組存儲
var x = new Array("星期日", "星期一", "星期二");
var x = x.concat("星期三","星期四", "星期五");
var x = x.concat("星期六");
var today_time = new Date(); //獲取今天的日期
//先后用中文表示的日期
document.all("today_time").innerText=today_time.getFullYear()+'年'+(today_time.getMonth()+1)+'月'+today_time.getDate()+'日\n'+x[today_time.getDay()];
</script>
</BODY>
</HTML>