源代码 :
点击运行
<!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"> </script> <script> // 获取节点的上一个同级节点 function get_previousSibling(n) { y=n.previousSibling; while (y.nodeType!=1) { y=y.previousSibling; } return y; } </script> </head> <body> <script> xmlDoc=loadXMLDoc("books.xml"); x=get_previousSibling(xmlDoc.getElementsByTagName("price")[0]); document.write(x.nodeName); </script> </body> </html>
运行结果