我使用Index.html
JQuery
动态内容
内部索引我有
<div id="main">
</div>
我有加载内容的脚本: -
function LoadPage(url) {
var req = false;
if (window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch (e) {
req = false;
}
} else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
req = false;
}
}
}
var element = document.getElementById("main");
if (!element) {
alert("Bad id " +
"passed to clientSideInclude." +
"You need a div or span element " +
"with this id in your page.");
return;
}
if (req) {
req.open('GET', url, false);
req.send(null);
element.innerHTML = req.responseText;
} else {
element.innerHTML =
"Sorry, your browser does not support " +
"XMLHTTPRequest objects. This page requires " +
"Internet Explorer 5 or better for Windows, " +
"or Firefox for any system, or Safari. Other " +
"compatible browsers may also exist.";
}
}
所以我可以将其用作<a href="#" onclick="LoadPage('home.html')" title="Home">
现在问题是,如果我加载了Home.html
而home.html有其他href
它无法正常工作,因为它看不到div
id="main"
,所以我的问我如何获得索引的div
并重新加载它,或者我该如何解决这个问题呢?