Javascript html5历史api可以在所有链接上工作,甚至在content div内部

Javascript html5历史api可以在所有链接上工作,甚至在content div内部,javascript,jquery,html,Javascript,Jquery,Html,有人能帮我解决这个问题吗?它在菜单上的链接上很有效,在div“content”之前,但是当尝试导航页面时,在div中被称为“content”的链接中,它确实有效 这是在不重新加载页眉的情况下加载页面 $(function(){ $("a[rel='tab']").click(function(e){ //e.preventDefault(); /* if uncomment the above line, html

有人能帮我解决这个问题吗?它在菜单上的链接上很有效,在
div
“content”之前,但是当尝试导航页面时,在
div
中被称为“content”的链接中,它确实有效

这是在不重新加载页眉的情况下加载页面

$(function(){
    $("a[rel='tab']").click(function(e){
        //e.preventDefault(); 
        /*  
        if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
        if commented, html5 nonsupported browers will reload the page to the specified link. 
        */

        //get the link location that was clicked
        pageurl = $(this).attr('href');

        //to get the ajax content and display in div with id 'content'
        $.ajax({url:pageurl+'?rel=tab',success: function(data){
            $('#content').html(data);
        }});

        //to change the browser URL to 'pageurl'
        if(pageurl!=window.location){
            window.history.pushState({path:pageurl},'',pageurl);    
        }
        return false;  
    });
});

/* the below code is to override back button to get the ajax content without reload*/
$(window).bind('popstate', function() {
    $.ajax({url:location.pathname+'?rel=tab',success: function(data){
        $('#content').html(data);
    }});
});

您应该处理用ajax加载的新锚

$(function(){
    $("a[rel='tab']").click(clickhandler);
});
$(window).on('popstate', function() {
    $.ajax({url:location.pathname+'?rel=tab',success: function(data){
        $('#content').html(data);
        $("#content a[rel='tab']").click(clickhandler);
    }});
});

var clickhandler = function(e){
    pageurl = $(this).attr('href');
    $.ajax({url:pageurl+'?rel=tab',success: function(data){
        $('#content').html(data);
        $("#content a[rel='tab']").click(clickhandler);
    }});

    if(pageurl!=window.location){
        window.history.pushState({path:pageurl},'',pageurl);    
    }
    return false;  
};
尝试使用$([rel='tab'])