var xmlhttp=null; function getWeather() { //var cityNameId=document.getElementById("cityNameId"); // var cityId=cityNameId.options[cityNameId.selectedIndex].text; // var id=cityId.substring(cityId.indexOf("(")+1,cityId.indexOf(")")); if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } xmlhttp.open("GET","http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName="+54161,true); xmlhttp.onreadystatechange=stateChange; xmlhttp.send(null); } function stateChange() { if(xmlhttp.readyState==4) { if(xmlhttp.status==200) { //获取所有返回的数据 var data=xmlhttp.responseXML; var weather= "城市:"+data.getElementsByTagName("string")[1].firstChild.nodeValue+"\n" +"温度:"+data.getElementsByTagName("string")[5].firstChild.nodeValue+"\n" +"天气:"+data.getElementsByTagName("string")[6].firstChild.nodeValue+"\n"; //+"实况:"+data.getElementsByTagName("string")[10].firstChild.nodeValue+"\n"; //alert(weather); // document.write(weather); document.getElementById("Weather").innerHTML=weather; } } }