如何获得另一页的div

时间:2013-07-24 19:45:52

标签: javascript html ajax dynamic-content

我使用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并重新加载它,或者我该如何解决这个问题呢?

0 个答案:

没有答案