日期:2014-05-16  浏览次数:20626 次

感觉没问题但就是运行不对的代码,请兄弟们看看
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   XHTML   1.0   Strict//EN "
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ">
<HTML   xmlns= "http:www.w3.org/1999/xhtml ">
<HEAD>
<TITLE> Parsing   XML   Responses   with   the   W3C   DOM </TITLE>
<META   NAME= "Generator "   CONTENT= "EditPlus ">
<META   NAME= "Author "   CONTENT= " ">
<META   NAME= "Keywords "   CONTENT= " ">
<META   NAME= "Description "   CONTENT= " ">
<script   language= 'javascript '>
var   xmlHttp;
var   requestType= " ";
function   createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new   ActiveXObject( "Microsoft.XMLHTTP ");
}
else   if(window.XMLHttpRequest)
{
xmlHttp=new   XMLHttpRequest();
}
}
function   startRequest(requestedList)
{
requestType=requestedList;
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open( "POST ", "parseXML.xml ",true);
xmlHttp.send(null);
}
function   handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200||xmlHttp.status==0)
{
if(requestType== "north ")
{
listNorthStates();
}
else   if(requestType== "all ")
{
var   xmlDoc=xmlHttp.responseXML;
alert(xmlDoc);
var   allStates=xmlDoc.getElementsByTagName( "state ")[0].firstChild.nodeValue;
//listAllStates();
}
}
}
}
function   listNorthStates()
{
var   xmlDoc=xmlHttp.responseXML;
var   northNode=xmlDoc.getElementsByTagName( "north ")[0];
var   out= "Northern   States ";
var   northStates=northNode.getElementsByTagName( "state ");

outputList( "Northern   States ",northStates);
}
function   listAllStates()
{
var   xmlDoc=xmlHttp.responseXML;
alert( "1 ");
var   allStates=xmlDoc.getElementsByTagName( "state ")[0].firstChild.nodeValue;
alert(northStates);
alert( "2 ");
outputList( "All   States   in   Document ",allStates);
}
function   outputList(title,states)
{
var   out=title;
var   currentState=null;
alert( "3 ");
for(var   i=0;i <states.length;i++)
{
alert( "4 ");
currentState=states[i].nodeValue;
out=out+ "\n- "+currentState;
}
alert( "1 "+out);
}

</script>
</HEAD>

<BODY>
<form   action= "# ">
<input   type= "button "   value= "View   All   Listed   States "   onclick= "startRequest( 'all '); "/>
<br/> <br/>
<input   type= "button "   value= "View   All   Listed   Northern   States "   onclick= "startRequest( 'north '); ">
</form>
</BODY&