0

-

我该如何处理它,让 Javascript 在 Ajax 调用之后正常工作?

在我的页面(wordpress)上 - 我在起始页上有所有帖子。我已经建立了一个过滤系统,用户可以使用它过滤特定内容之后的帖子——比如“最新的、查看最多的、突出显示的”

我使用下面的这个函数来使这个过滤器工作:

 <script type="text/javascript">
    $(document).ready(function(){
    $.ajaxSetup({cache:false});
    $("#new").click(function(){

        var post_id = $(this).attr("rel")
        $(".postbox_wrapper").html('<span class="filter_posts">
<img src="<?php bloginfo ('template_directory'); ?>/images/287.gif"></span>');
        $(".postbox_wrapper").load(jQuery(this).attr("href") + " .postbox_wrapper")
        return false;
    });
});

访问者点击“新建”按钮,帖子被过滤——只显示最新的帖子。但是我使用 Javascript 来统计 disqus、惰性图像加载器等的帖子计数。这些 JS 文件不会加载到过滤后的帖子上。(分类法.php)

这是例如一个 JS 文件,这对于使惰性加载器可用于过滤的帖子是必要的:

http://myurl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0

问题是:我如何在上面的函数中知道,在新加载的“过滤”页面上也使用 JS 脚本。

有点像这样:Use Ajax() function in Jquery to load PART of an external page into div

但我没有让它工作....

多谢!

4

1 回答 1

0

我不确定我是否理解你的问题。您是否尝试在 div 中加载特定内容后加载脚本?

如果是这样试试:

$(function(){
    $.ajaxSetup({cache:false});

    $("#new").click(function(){
        var $this = $(this);
        var $PostboxWrapper = $(".postbox_wrapper");

        var post_id = $this.attr("rel")

        //I think you want load something like a loading .gif in taht point. Right?
        $PostboxWrapper.html(
            "<span class='filter_posts'>" + 
            "   <img src='<?php bloginfo ('template_directory'); ?>/images/287.gif'>" +
            "</span>"
        );

        $(".postbox_wrapper").load(jQuery(this).attr("href"), function()
        {
            $.getScript(
                "http://yourUrl/../plugins/bj-lazy-load/js/bjll.min.js?ver=0.4.0",
                function(data, textStatus, jqxhr) {
                    console.log('Load was performed.');
                }
            );
        })
        return false;
    });
});
于 2012-07-21T13:36:11.580 回答