如何用JS把XML文件里的数据读取到HTML上? 在下刚接触到这一方面,哪位大侠点通一下!感激不尽!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参见http://www.jslab.org.cn源代码 可以通过xml文件对象和ajax两种方法来实现,ajax实现最可靠,几乎所有浏览器都可以支持,而用xml文件对象的方法只能在ie和firefox/mozilla浏览器下实现<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">function $(sId){ return document.getElementById(sId);}function outputXml(oRoot){ var aItems=oRoot.getElementsByTagName("*"); var i,nLen=aItems.length; var oLi,oUl=$("ul1"); for(i=0;i<nLen;i++){ oLi=document.createElement("li"); oLi.innerHTML=aItems[i].getAttribute("label"); oUl.appendChild(oLi); }}function loadDate(){ var rootNode; var xmlDoc=document.all ?new ActiveXObject('Msxml2.DOMDocument') :document.implementation.createDocument("", "", null); try{ xmlDoc.async=false; xmlDoc.load('data.xml'); rootNode=xmlDoc.documentElement; outputXml(rootNode); }catch(e){ alert("发生错误:"+e); }}window.onload=function(){ loadDate();}</script></head><body><ul id="ul1"></ul></body></html> <?xml version="1.0" encoding="utf-8"?><items> <item id="i1" label="标题一"/> <item id="i2" label="标题二"/> <item id="i3" label="标题三"/> <item id="i4" label="标题四"/> <item id="i5" label="标题五"/> <item id="i6" label="标题六"/> </items> 一个tabpanel,欢迎下载 两道面试题 一个简单的js定时切换选项卡问题 window.open()方法如何在新打开窗口中添加内容 Microsoft.XMLDOM 读取xML的问题 求人找出这个js文件与prototype的冲突,并解决 急问 dtree的问题 拜托帮帮忙...很急.. 大家怎么做项目进度和工作进度估算的? 关于JAVA WEB中使用EASYUI技术,accordion菜单select问题? 那能找到模仿WINDOWS界面的代码??谢谢各位DX了 .do文件是如何生成的? 在win系统测试正常,但在liunx下出现了问题
的方法只能在ie和firefox/mozilla浏览器下实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function $(sId){
return document.getElementById(sId);
}function outputXml(oRoot){
var aItems=oRoot.getElementsByTagName("*");
var i,nLen=aItems.length;
var oLi,oUl=$("ul1");
for(i=0;i<nLen;i++){
oLi=document.createElement("li");
oLi.innerHTML=aItems[i].getAttribute("label");
oUl.appendChild(oLi);
}
}function loadDate(){
var rootNode;
var xmlDoc=document.all
?new ActiveXObject('Msxml2.DOMDocument')
:document.implementation.createDocument("", "", null);
try{
xmlDoc.async=false;
xmlDoc.load('data.xml');
rootNode=xmlDoc.documentElement;
outputXml(rootNode);
}catch(e){
alert("发生错误:"+e);
}
}window.onload=function(){
loadDate();
}
</script>
</head>
<body>
<ul id="ul1">
</ul>
</body>
</html>
<items>
<item id="i1" label="标题一"/>
<item id="i2" label="标题二"/>
<item id="i3" label="标题三"/>
<item id="i4" label="标题四"/>
<item id="i5" label="标题五"/>
<item id="i6" label="标题六"/>
</items>