运行的时候为什么提示Object #<Document> has no method 'load'?? javascript 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 加载xml文件最好使用xmlhttp。兼容性好处理。rsponseXML表示xml对象 兼容 IE、Firefox、Chrome、Safari、Opera 等浏览器的 XML 文件加载方式代码如下,xml 文件名为 1.xml。1.XML代码<?xml version="1.0" encoding="utf-8"?><note><t1><title>孟子E章的网站</title><url>http://dotnet.aspx.cc/</url></t1><t1><title>孟宪会的博客</title><url>http://blog.csdn.net/net_lover/</url></t1></note> HTML 代码<script type="text/javascript"> var xmlDoc = null, xmlhttp = null; function loadXML() { xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp"); if (xmlhttp == null) { alert("你的浏览器不支持 XMLHttpRequest"); return; } xmlhttp.open("GET", "1.xml?" + Date.parse(new Date()), true); xmlhttp.setRequestHeader("Content-Type", "text/xml"); xmlhttp.onreadystatechange = getmessage; xmlhttp.send(null); } function getmessage() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { xmlDoc = xmlhttp.responseXML.documentElement; if (xmlDoc == null) { alert("返回的数据不正确。"); return; } var nodes = xmlDoc.getElementsByTagName("t1") tb = document.getElementById("table_note"); tbody = document.createElement("tbody") for (i = 0; i < nodes.length; i++) { tr = document.createElement("tr") td = document.createElement("td") td.innerHTML = nodes[i].getElementsByTagName("title")[0].childNodes[0].nodeValue tr.appendChild(td) td = document.createElement("td") url = nodes[i].getElementsByTagName("url")[0].childNodes[0].nodeValue; td.innerHTML = "<a href='" + url + "'>" + url + "</a>" tr.appendChild(td) tbody.appendChild(tr) } tb.appendChild(tbody) } }</script></head><body onload="loadXML()"> <table id="table_note" border="1"> <tr> <td>姓名</td> <td>网址</td> </tr> </table></body></html> 由老孟这位csdn大牛指点你,你再学不好对的起谁呀 老孟这位csdn大牛指点你,你再学不好对的起谁呀 老孟您好。请问下XML 如何在不通过IIS 的情况下直接被获取。。因为我需要用opera浏览器。。但是目前只有FF 可以获取到。。您的代码我复制了。。直接用opera打开也是获取不到数据的。。 不通过IIS 的情况下直接被获取?文件要放在web server上,你的xml文件要放在什么位置? 大神写的复杂了点,以下是给小白的写法function loadXMLDoc(dname){if (window.XMLHttpRequest){xhttp=new XMLHttpRequest();}else{xhttp=new ActiveXObject("Microsoft.XMLHTTP");}xhttp.open("GET",dname,false);xhttp.send();return xhttp.responseXML;}修改loadXMLDoc即可 使用jQuery 实现3文本框修改数字后无刷新运算显示新结果 先提交 再跳转 如何给setInterval里的函数加参数?奇怪了 可编辑div过滤粘贴内容格式 document下的对象为空或不是对象(急!!) 得到框架的location.... ★★★请问各位老师如何在页面中使用脚本得到该页面所有的CheckBox集合★★★ 求一标签!先谢谢啦!!! 如何查询出文件夹中包含的文件名和文件数? 各位请问在javascript中去掉前后空格的函数是什么??帮帮忙!初学者! 焦点图现在就差一个自动播放功能,写了,但是不能自动播放,大家帮我看看哪儿出的问题 onload 事件
rsponseXML表示xml对象
代码如下,xml 文件名为 1.xml。1.XML代码
<?xml version="1.0" encoding="utf-8"?>
<note>
<t1>
<title>孟子E章的网站</title>
<url>http://dotnet.aspx.cc/</url>
</t1>
<t1>
<title>孟宪会的博客</title>
<url>http://blog.csdn.net/net_lover/</url>
</t1>
</note>
HTML 代码
<script type="text/javascript">
var xmlDoc = null, xmlhttp = null;
function loadXML() {
xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
if (xmlhttp == null) {
alert("你的浏览器不支持 XMLHttpRequest");
return;
}
xmlhttp.open("GET", "1.xml?" + Date.parse(new Date()), true);
xmlhttp.setRequestHeader("Content-Type", "text/xml");
xmlhttp.onreadystatechange = getmessage;
xmlhttp.send(null);
} function getmessage() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
xmlDoc = xmlhttp.responseXML.documentElement;
if (xmlDoc == null) {
alert("返回的数据不正确。");
return;
}
var nodes = xmlDoc.getElementsByTagName("t1")
tb = document.getElementById("table_note");
tbody = document.createElement("tbody")
for (i = 0; i < nodes.length; i++) {
tr = document.createElement("tr")
td = document.createElement("td")
td.innerHTML = nodes[i].getElementsByTagName("title")[0].childNodes[0].nodeValue
tr.appendChild(td)
td = document.createElement("td")
url = nodes[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
td.innerHTML = "<a href='" + url + "'>" + url + "</a>"
tr.appendChild(td)
tbody.appendChild(tr)
}
tb.appendChild(tbody)
}
}
</script>
</head>
<body onload="loadXML()">
<table id="table_note" border="1">
<tr>
<td>姓名</td>
<td>网址</td>
</tr>
</table>
</body>
</html>
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}修改loadXMLDoc即可