0

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内容,它将无法工作,因为它看不到divwith id="main",所以我的问题是如何获取div索引并重新加载它,或者我该如何解决这个问题?

4

0 回答 0