求助。十分火急!!!!!!!!!如何访问,XML中的元素,(用JAVASCRIPT)只能访问第一个和第二个数据,请教高手我那里错了吗.十分急. <html> <head> <title>不刷新页面查询的方法</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <script language="JavaScript"> //将数据岛中数据装入列表框 function loadinsel() { //分别存放料号,和品名 var Employeeid,Employeelastname,guige; root=document.all.xmlemployees.childNodes.item(0); for(i=0;i<root.childNodes.length;i++) { getnode=root.childNodes(i); Employeeid=root.childNodes(i).getAttribute("emid");//得到料号 for(j=0;j<getnode.childNodes.length;j++) { employeeinf=getnode.childNodes(j).nodeName; //得到品名 if(employeeinf=="lastname") { Employeelastname=getnode.childNodes(j).text; } }
for(k=0;k<getnode.childNodes.length;k++)//得到规格 { employeeinf=getnode.childNodes(k).nodeName; if(employeeinf=="lastname") { guige=getnode.childNodes(k).text; } }
if(Employeeid!="" && Employeelastname!=""&& guige!="") { //将得到的雇员名和雇员ID写到SELECT中 findcontent.value=Employeeid guige.value=guige; liaohao.value=Employeelastname } } } function findemployee() { var Employeelastname,Employeeid,guige;//存放料号,存放品名 Employeelastname=""; Employeeid=""; guige=""; findtext=window.findcontent.value;//获取查询对像
root=window.xmlemployees.childNodes(0); //得到料号 for(i=0;i<root.childNodes.length;i++) { getitem=root.childNodes(i); Employeeid=root.childNodes(i).getAttribute("emid");
for(j=0;j<getitem.childNodes.length;j++) { if(getitem.childNodes(j).nodeName=="lastname")//比较运算 { employee_temp=getitem.childNodes(j).text; //得到了品名 }
//查找匹配项 if(Employeeid==(findtext)) { Employeelastname=employee_temp; } } }
if(Employeeid!="" && Employeelastname!="") { liaohao.value=Employeelastname;
} } </script> <body bgcolor="#FFFFFF" text="#000000" onLoad="javascript:loadinsel()"> <table width="100%" border="0"> <tr> <td> <input name="findcontent" type="text"onBlur="javascript:findemployee()" size="15"> <label> <input name="liaohao" type="text" size="10"> <input name="guige" type="text" size="10"> </label> </td> </tr> </table>
<xml id="xmlemployees"> <employee>
<employeeitem emid="1"> <lastname>后板素材1</lastname > <guigenumber>SECC</guigenumber> <content>魔方一号</content> </employeeitem>
<employeeitem emid="2"> <lastname>后板素材2</lastname > <guigenumber>SECC 384*192*0。6mm</guigenumber> <content>魔方一号</content> </employeeitem>
<employeeitem emid="3"> <lastname>超级材料3</lastname > <guigenumber>10000000000000KM</guigenumber> <content>成能材料</content> </employeeitem>
<employeeitem emid="4"> <lastname>超级材料4</lastname > <guigenumber>fdasfsda</guigenumber> <content>fasdfasdfasdf</content> </employeeitem>
<employeeitem emid="5"> <lastname>超级材料5</lastname > <guigenumber>asdasdas</guigenumber> <content>dasdas</content> </employeeitem>
<employeeitem emid="6"> <lastname>超级材料6</lastname > <guigenumber>dasd</guigenumber> <content>dasdas</content> </employeeitem>
<employeeitem emid="7"> <lastname>超级材料7</lastname > <guigenumber>fasdfasd</guigenumber> <content>fasdfads</content> </employeeitem>
<employeeitem emid="8"> <lastname>超级材料8</lastname > <guigenumber>rwerwe</guigenumber> <content>rwerwer</content> </employeeitem>
<employeeitem emid="9"> <lastname>超级材料9</lastname > <guigenumber>dasdasd</guigenumber> <content>dasasdas</content> </employeeitem>
<employeeitem emid="10"> <lastname>超级材料10</lastname > <guigenumber>dasd</guigenumber> <content>dasd</content> </employeeitem>
<employeeitem emid="11"> <lastname>超级材料11</lastname > <guigenumber>dasd</guigenumber> <content>dasdas</content> </employeeitem>
<employeeitem emid="12"> <lastname>超级材料12</lastname > <guigenumber>dasdas</guigenumber> <content>dasdas</content> </employeeitem>
<employeeitem emid="13"> <lastname>超级材料13</lastname > <guigenumber>423</guigenumber> <content>4322323</content> </employeeitem>
<employeeitem emid="14"> <lastname>超级材料14</lastname > <guigenumber>fds</guigenumber> <content>fasdasdf</content> </employeeitem>
</employee> </xml>
</body> </html>