如何使用.load()防止主页加载到自身

时间:2012-04-09 22:38:02

标签: javascript jquery

我有以下js:

$(function() {
    $('#header a').click(function() {
        $('#contentspace').empty();
        // $("#contentspace").load(eventUrl + "#content");
        $("#contentspace").load(this.href, + ' #content', function(response){
            console.log($('#content', response).html())
            event.preventDefault();
        });
    });
});

和html:

<div id="header" class="ui-corner-all ui-buttonset">
    <a title="index" href="index.php" ><span>home</span></a>
    <a title="code" href="code.php" ><span>code</span></a>
    <a title="design" href="design.php" ><span>design</span></a>
    <a title="illustration" href="illustration.php" ><span>illustration</span></a>
    <a title="writing" href="writing.php" ><span>writing</span></a>
    <a title="links" href="links.php" ><span>links</span></a>
    <a title="about" href="about.php" ><span>about</span></a>
</div>

我使用它将网页的各个部分加载到#contentspace,并为我的练习网站提供ajax的感觉。当用户点击返回主页面并且主页面本身被加载时,就会出现问题。我以为我可以通过在- ' #header',参数中添加.load来修复它,但这似乎没有做任何事情,即使它已经可以看到它会如何产生其他问题。< / p>

摘要:我在使用jquery创建有效的登录页面时遇到问题。主页正在加载它的页眉和页脚。

1 个答案:

答案 0 :(得分:1)

也许您可以将主页分为index.htmlhome.html,索引只包含页眉和页脚,另一个只包含主页面的内容。

然后,当页面最初加载时(例如,在您将点击处理程序附加到导航之前),您可以让索引使用“home.html”执行.load一次。