我试图在每次单击链接时根据它的href加载不同的xml文件。 我在头下面:使用JavaScript解析XML文件中的变量点击
JAVASCRIPT
window.onload=function() {
loadXMLDoc("papers.xml"); // loads the default xml file so that page is not empty
}
function scanForXML(){
var extLinks=document.getElementById('results_list').getElementsByTagName('a');
for (i=0; i<extLinks.length; i++) {
extLinks[i].onclick=function getName()
{
var fileName=this.getAttribute('href');
loadXMLDoc(fileName);
return false;
}
}
}
HTML
<ol id="results_list">
<li> <a class="tooltip" href="paper2.xml"> Teaching with Tablet PC's </a></li>
<li> <a href="paper3.xml" class="tooltip"> Tablet PC’s as Instructional Tools </a></li>
</ol>
onclick事件的作品,我得到href值,但新XMLFILE不会被加载。 任何想法为什么?
ps:no jquery plz,不能使用它。想更好地学习基本的JavaScript
的JavaScript load码 - 顺便说一下它不会在Chrome和Opera的工作 - 但工程的默认XML文件中的Safari浏览器被加载 代码:
function loadXMLDoc(dname)
{
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",dname,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
谢谢! K
可能的重复[不能在jQuery的.ajax方法中使用返回的数据,除了函数本身](http://stackoverflow.com/questions/11247066/cant-use-returned-data-in-ajax- jquery-anywhere-but-the-function-itse) –