varxmlHttp;functioncreatXMLHttpRequest()
{if(window.ActiveXObject){xmlHttp=newActiveXObject("Microsoft.XMLHTTP");}else if(window.XMLHttpRequest){xmlHttp=newXMLHttpRequest();}
}functionupdateSelect()
{varselected=document.all.slt1.value;
creatXMLHttpRequest();
xmlHttp.onreadystatechange=processor;
xmlHttp.open("GET","CreatXML?selected="+selected);
xmlHttp.send(null);
}functionprocessor()
{varresult;if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
result=xmlHttp.responseXML.getElementsByTagName("city");while(document.all.slt2.length>0){ document.all.slt2.removeChild(document.all.slt2.childNodes[0]);}/*childNodes指所有子节点(包括文本节点和元素节点),当你代码这么写:博士~~~本科~~~ //这里select和option之间,option和option之间有空白,这段空白就是文本节点;childNodes[0]指得是中间那段空白(文本节点),nodeName是#text;childNodes[1]为“博士”,nodeName是OPTION;childNodes[2]为空白,nodeName是#text;以此类推;可以用children(只获取元素节点)来代替childNodes*/
for(vari=0;i
{varoption=document.createElement('option');
option.text=result[i].children[0].childNodes[0].nodeValue;
option.value=result[i].children[1].childNodes[0].nodeValue;
document.all.slt2.options.add(option,null);
}
}
}
hunan
guangdong
choose your city