0

在网页上,当您单击链接时,会使用 .load 函数获取该页面的内容。如果什么都没有找到,那么什么也不会发生。现在的问题是,如果您从一页转到下一页,然后再返回,则代码不起作用。

访问我的测试站点要容易得多 - http://joshblease.co.uk/JQuery/

  1. 点击橙色链接“页面”
  2. 点击标题链接“索引”
  3. 现在再次点击橙色的“页面”链接

页面刷新,我不知道为什么?

编辑:我目前正在使用 Chrome 进行测试

编辑:我的代码

function JLoad (url, elem, type) {
    if(type != "ext"){
        var $link = elem;
        var uri = url + ' #content';
        $("#content").load(uri, {'body_only': '1'}, function(response, status, xhr){
            if (status != "error") {
                if (window.history && window.history.pushState){
                    window.history.pushState({}, 'JoshBlease Test', url);
                }else{
                        window.location.hash='!/'+url;
                }
                if(type == "menu"){
                    $("a").removeClass("active");
                    $link.addClass("active");
                }
            }else{
                if(type == "menu"){
                    var linkText = $link.text();
                    $link.fadeOut(function(){$link.addClass("notFound").text("404 Error")}).fadeIn().delay(2000).fadeOut(function(){$link.removeClass("notFound").text(linkText)}).fadeIn();
                }
            }
        });
    }
};

这是在页面的标题中:

$(document).ready(function() {
    $("a").on("click", function(event) {
        console.log("Click");
        event.preventDefault();
        var url = $(this).attr("href").replace('./', '');
        JLoad(url, $(this), $(this).attr("type"));
        return false;
    });
});

正在使用的链接:

<a href="page.php" type="content">Page</a>
4

1 回答 1

0

我不知道为什么,但是通过使用旧版本的 JQuery,我将“on”事件替换为“live”。现在好像可以了?

于 2013-06-06T22:04:58.323 回答