日期:2014-05-20 浏览次数:20698 次
<html> <body> <h1>W3School.com.cn Internal Note</h1> <p> <b>To:</b> <span id="to"></span><br /> <b>From:</b> <span id="from"></span><br /> <b>Message:</b> <span id="message"></span> </p> <script type="text/javascript"> 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","/example/xmle/note.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("to").innerHTML= xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML= xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML= xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue; </script> </body> </html> XML: <?xml version="1.0" encoding="ISO-8859-1"?> <!-- Copyright w3school.com.cn --> -<note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
------解决方案--------------------
都懂?真懂假懂啊!
原原本本的copy不就OK了
<script type="text/javascript"> function showtext(){ 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","note.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var text = xmlDoc.getElementsByTagName("Text")[0].childNodes[0].nodeValue; alert(text); } </script>
------解决方案--------------------
我在IE6,IE9和firefox测试可以。其它版本的IE不知道。