触发jQuery分页后灯箱不再工作(jQuery和灯箱冲突)



我们同时使用两个脚本:pretypto和jQuery分页。当页面首次加载时,两个脚本都在工作。但是,当我点击分页的第2页时,灯箱不再显示,但我仍然可以从一个页面跳转到下一个页面。以下是两个脚本的初始化脚本:

jQuery分页:

<script type="text/javascript">
            // This is a very simple demo that shows how a range of elements can
            // be paginated.
            // The elements that will be displayed are in a hidden DIV and are
            // cloned for display. The elements are static, there are no Ajax 
            // calls involved.
            /**
             * Callback function that displays the content.
             *
             * Gets called every time the user clicks on a pagination link.
             *
             * @param {int} page_index New Page index
             * @param {jQuery} jq the container with the pagination links as a jQuery object
             */
            function pageselectCallback(page_index, jq){
                var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
                $('#Searchresult').empty().append(new_content);
                return false;
            }
            /** 
             * Initialisation function for pagination
             */
            function initPagination() {
                // count entries inside the hidden content
                var num_entries = jQuery('#hiddenresult div.result').length;
                // Create content inside pagination element
                $("#Pagination").pagination(num_entries, {
                    callback: pageselectCallback,
                    items_per_page:1 // Show only one item per page
                });
             }
            // When document is ready, initialize pagination
            $(document).ready(function(){                  
                initPagination();
            });
</script>

prettyPhoto:

<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto();
  });
</script>

谁知道冲突在哪里?谢谢。

我找到了一个解决我的问题的方法(我在另一个论坛上找到的):

我只需要插入$("a[rel^=' pretypto ']"). pretypto ();在函数pageselectCallback中,像这样:

function pageselectCallback(page_index, jq){
                var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
                $('#Searchresult').empty().append(new_content);
                $("a[rel^='prettyPhoto']").prettyPhoto();
                return false;
            }

如果我只能给这个回答问题的人+1。:)

尝试使用Jquery .delegate()

$("a").delegate("[rel^='prettyPhoto']", "load", function()
    {
        $("a[rel^='prettyPhoto']").prettyPhoto();
    });

最新更新