我想在点击按钮上加载不同的XML文件。如何将其发送到该功能?
<button onclick = 'loadXMLDoc(a.xml)'></button>
<button onclick = 'loadXMLDoc(b.xml)'><button>
<script>
function loadXMLDoc(a) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "a", true);
xmlhttp.send();
}
</script>
答案 0 :(得分:0)
您的javascript调用需要传递字符串,第二个<button>
也未关闭,请查看:
<button onclick = "loadXMLDoc('a.xml')"></button>
<button onclick = "loadXMLDoc('b.xml')"></button>
<script>
function loadXMLDoc(a) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
}
xmlhttp.open("GET", a, true);
xmlhttp.send();
}
</script>