我已经尝试了几个小时,只想弄清楚,如何解决问题。它是一个包含html的脚本,其id为" incl"和一个名为" file"的自定义属性在javascript中。它又回来了
"未捕获的TypeError:无法设置属性' innerHTML'为null
在XMLHttpRequest.xhttp.onreadystatechange(includer.js:13)"
我的剧本是:
var all = document.getElementsByTagName("*");
var fle = [];
var Incl = [];
var nIncl = [];
var xhttp = new XMLHttpRequest();
for (var i = 0, max = all.length; i < max; i++) {
Incl[i] = all[i].getAttribute("id");
if (Incl[i] == "incl") {
nIncl[i] = all[i].getAttribute("id");
fle[i] = all[i].getAttribute("file");
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(nIncl[i]).innerHTML = this.responseText;
}
};
xhttp.open("GET", fle[i], true);
xhttp.send();
}
}
&#13;
<head id='incl' file="header.html"></head>
<body>
<div id="incl" file="Navlist.txt"></div>
</body>
&#13;