0

また。まあ、私はpushStateスクリプトもやっています.jquery 1.6.2でやっていましたが、.live()で動作していましたが、jqueryのv2.0.3では非推奨です。だから、どうやってそれを置き換えることができるのかわからない、見て:

$('.a').live('click', function(e){
        history.pushState(null, null, this.href);
        replacePag(this.href);
        e.preventDefault();
        $(window).bind('popstate', function(){
        replacePag(location.pathname);
    });
    });

クラス .a の 1 つの要素で実行すると正常に動作しますが、私のページには多くの .a 要素があります。.on() で試しましたが、どちらも機能しません。

$('.a').on('click', function(e){
            history.pushState(null, null, this.href);
            replacePag(this.href);
            e.preventDefault();
            $(window).bind('popstate', function(){
            replacePag(location.pathname);
        });
        });

あなたが私を助けることができるなら、あなたの助けに感謝します.

さて、私のスクリプトは次のとおりです。

$(function(){
    var replacePag = function(ur) {
        $.ajax({
            url: ur,
            type: 'get',
            dataType: 'html',
            success: function(dat){
                var domm = $(dat);
                var titl = domm.filter('title').text();
                var htm = domm.filter('#body').html();
                $("#body").fadeOut(100,
                function(){
                    $(this).html(htm);
                    $('title').text(titl);
                    }).fadeIn( 1000 );
            }
        });
    }

    $('.a').live('click', function(e){
        history.pushState(null, null, this.href);
        replacePag(this.href);
        e.preventDefault();
        $(window).bind('popstate', function(){
        replacePag(location.pathname);
    });
    });
});
4

2 に答える 2