0

我在我的网站上使用了两个脚本

  1. jQuery/Ajax 在不重新加载页面的情况下加载接下来的三个帖子
  2. jQuery 在 iF​​rame/modal 对话框中打开每个帖子

问题是:点击“加载更多帖子”后,然后点击前3个帖子中的一个,帖子被打开两次。

我需要找到一种方法来删除前一个占位符的函数 superbox() 并为新的占位符再次添加它(否则新帖子只会在普通窗口中打开)。

该网站是http://gotoviproekti-och.com

    if(pageNum <= max) {
    // Insert the "More Posts" link.
    $('.content-middle')
        .append('<div class="pbd-alp-placeholder-'+ pageNum +'"></div>')            

        .append('<p id="pbd-alp-load-posts"><a href="#">Покажи още готови проекти</a></p>');

    $(function(){
        $.superbox();
        });
        //Single Page Carousel
        $(function() {
        $(".image").click(function() {
        var image = $(this).attr("rel");
        $('#image').hide();
        $('#image').fadeIn('slow');
        $('#image').html('<img src="' + image + '"/>');
        return false;
            });
        });
    }



/**
 * Load new posts when the link is clicked.
 */
$('#pbd-alp-load-posts a').click(function() {

    // Are there more posts to load?
    if(pageNum <= max) {

        // Show that we're working.
        $(this).text('Loading...');

        $('.pbd-alp-placeholder-'+ pageNum).load(nextLink + ' .pic',
            function() {
                // Update page number and nextLink.
                pageNum++;
                nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);

                // Add a new placeholder, for when user clicks again.
                $('.content-middle')
                .append('<div class="pbd-alp-placeholder-'+ pageNum +'"></div><div class="clearfloat"></div>')

                $.superbox.detach();

                $.superbox();


                // Update the button message.
                if(pageNum <= max) {
                    $('#pbd-alp-load-posts a').text('Load more posts');
            }
        );
    } else {
        $('#pbd-alp-load-posts a').append('.');
    }   

    return false;
});

});

4

1 回答 1

1

使用$.on(),您只需绑定一次事件。

$('#posts-container').on('click', '.post', doPostEvent);
于 2012-05-07T15:30:22.423 回答