index.html
<script >
function loadPage(){
var xhttp,rtext,x;
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function(){
if (xhttp.readyState == 4 && xhttp.status == 200) {
rtext=xhttp.responseText;
x = rtext.getElementById('bottom');
}
document.getElementById("firstdiv").innerHTML=x;
};
xhttp.open("GET","first.html",true);
xhttp.send();
}
</script>
<body>
<div onClick="loadPage();">Home</div>
<div id="firstdiv"></div>
</body>
first.html
<body>
<div id="bottom">
<p>content 1</p>
</div>
<div id="bottom1">
content 2
</div>
</body>
我只需要從first.html加載「底部」div到我的索引頁面,僅使用javascript並面臨錯誤。使用Javascript從另一個頁面加載特定內容
的getElementById( '底部')沒有被定義屬性。
如何繼續?