| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 825 人关注过本帖
标题:求助。十分火急!!!!!!!!!如何访问,XML中的元素,(用JAVASCRIPT)只能访问第一 ...
只看楼主 加入收藏
好大一条虫
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-7-15
收藏
 问题点数:0 回复次数:2 
求助。十分火急!!!!!!!!!如何访问,XML中的元素,(用JAVASCRIPT)只能访问第一个和第

求助。十分火急!!!!!!!!!如何访问,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>

搜索更多相关主题的帖子: XML 火急 JAVASCRIPT 元素 
2005-07-15 15:25
好大一条虫
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-7-15
收藏
得分:0 

 没人罗我自己来
2005-07-18 08:08
好大一条虫
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-7-15
收藏
得分:0 
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; } }

if(Employeeid!="" && Employeelastname!=""&& guige!="") { //将得到的雇员名和雇员ID写到SELECT中 findcontent.value=Employeeid guige.value=guige; } } } 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>

2005-07-18 08:11
快速回复:求助。十分火急!!!!!!!!!如何访问,XML中的元素,(用JAVASCRIPT)只能访 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017551 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved