实例首页
自学教程
IT工具箱
源代码
下载代码
上下布局
点击运行 >
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>自学教程(runoops.com)</title> <script> function loadXMLDoc(url) { if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码 xmlhttp = new XMLHttpRequest(); } else { // IE6, IE5 浏览器执行代码 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { txt = "<table border='1'><tr><th>Title</th><th>Artist</th></tr>"; x = xmlhttp.responseXML.documentElement.getElementsByTagName("CD"); for (i = 0; i < x.length; i++) { txt = txt + "<tr>"; xx = x[i].getElementsByTagName("TITLE"); try { txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>"; } catch (er) { txt = txt + "<td> </td>"; } xx = x[i].getElementsByTagName("ARTIST"); try { txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>"; } catch (er) { txt = txt + "<td> </td>"; } txt = txt + "</tr>"; } txt = txt + "</table>"; document.getElementById('txtCDInfo').innerHTML = txt; } } xmlhttp.open("GET", url, true); xmlhttp.send(); } </script> </head> <body> <div id="txtCDInfo"> <button onclick="loadXMLDoc('//demo.runoops.com/sources/xml/cd_catalog.xml')">获取 CD 信息</button> </div> </body> </html>
运行结果: