编辑您的代码:提交代码

x
 
1
 
2
 
3
<html>
4
<head>
5
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"> 
6
</script>
7
</head>
8
<body>
9
<script type="text/javascript">
10
//check if the last node is an element node
11
function get_lastchild(n)
12
{
13
var x=n.lastChild;
14
while (x.nodeType!=1)
15
  {
16
  x=x.previousSibling;
17
  }
18
return x;
19
}
20
21
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
22
23
var x=xmlDoc.documentElement;
24
var lastNode=get_lastchild(x);
25
26
for (var i=0;i<lastNode.childNodes.length;i++)
27
{ 
28
if (lastNode.childNodes[i].nodeType==1)
29
  { 
30
  //Process only element nodes
31
  document.write(lastNode.childNodes[i].nodeName);
32
  document.write(" = ");
33
  document.write(lastNode.childNodes[i].childNodes[0].nodeValue);
34
  document.write("<br />");
35
  } 
36
}
37
38
</script>
39
</body>
40
</html>
41
            

查看结果:

请在上面的文本框中编辑您的代码,然后单击提交按钮测试结果。w3c0.com

W3c0.com 提供的内容仅用于培训。我们不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。W3c0 简体中文版的所有内容仅供测试,对任何法律问题及风险不承担任何责任。 当使用本站时,代表您已接受了本站的使用条款和隐私条款。版权所有,保留一切权利。 鲁ICP备15022115号