我刚刚开始了解XMLHttpRequest并从JavaScript文件中获取XML文件中的数据,所以我一直在摆弄这段代码(从W3C site, on displaying XML data),并以此结尾:XML数据不会进入子元素
<style>
div[ui="note"] {
border: 1px solid #999;
color: red;
}
</style>
</head>
<div ui="panel-area">
<div ui="panel">
<div ui="note">
<strong>Content should be here</strong>
</div>
</div>
</div>
<script>
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","xml.xml",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var x = xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.querySelector('div[ui="panel"]').innerHTML += "<div ui='note'><strong>Content should be here</strong>";
document.querySelector('div[ui="panel"]').innerHTML += x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue;
}
document.querySelector('div[ui="panel"]').innerHTML +="</div>";
</script>
</body>
XML:
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<CD>
<ARTIST>Bob Dylan</ARTIST>
</CD>
<CD>
<ARTIST>Bonnie Tyler</ARTIST>
</CD>
<!-- Lots more names -->
</CATALOG>
这将艺术家名创建<div ui="note">
下它,但问题是,我不能让它去<div ui="note">
内:
This is the image of the result
有没有什么办法让内容在便笺格(无表请) - 不依赖于特殊的一个浏览器的功能,并会在移动Safari浏览器上工作?
你应该避免同步的XMLHttpRequest - 火狐30的他们被认为是不用 –