获取对象节点的值-javascript
我是新手。。想知道为什么在表中我得到了一个名为“[object node]”的东西,而不是实际值获取对象节点的值-javascript,javascript,Javascript,我是新手。。想知道为什么在表中我得到了一个名为“[object node]”的东西,而不是实际值 <script type="text/javascript"> window.onload = wonfunction; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code
<script type="text/javascript">
window.onload = wonfunction;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","sc2xml.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
function wonfunction() {
var homestead = xmlDoc.getElementsByTagName("sc2cash");
document.getElementById('num1').innerHTML = homestead[0];
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<table width="200" border="1">
<tr>
<td>Players</td>
<td id="num1"></td>
</tr>
<tr>
<td> </td>
<td> </td>
window.onload=won函数;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
open(“GET”,“sc2xml.xml”,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
函数{
var homestad=xmlDoc.getElementsByTagName(“sc2cash”);
document.getElementById('num1')。innerHTML=homestad[0];
}
无标题文件
球员
要回答您的评论:
至少在IE8中,您可以使用节点的.text
属性,如下所示:
var myNodes = xmlDoc.getElementsByTagName('node');
document.getElementById('result').innerHTML = myNodes[0].text;
一些好的文章是好的,也有一些好的例子
这在IE8中运行得很好。啊,是的,我找到了。文本内容正是我想要的。。但我想知道如何让它在IE中工作??