2011-07-08 59 views
2

我们同时使用两个脚本:prettyPhotojQuery pagination。第一次加载页面时,两个脚本都在工作。但是,当我点击分页的第2页时,灯箱不再显示,但我仍然可以从一页到另一页。这些都为双方的初始化脚本:灯箱在jQuery分页被触发后不再有效(jQuery和lightbox冲突)

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> 

任何人都知道在哪里的冲突是?谢谢。

回答

2

,我发现我的问题的解决方案(我在另一个论坛找到):

我只需要插入$(“一[相对^ =”prettyPhoto “]“)prettyPhoto();功能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到谁回答了here的家伙。 :)

1

尝试使用jQuery .delegate()

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

     $("a[rel^='prettyPhoto']").prettyPhoto(); 

    }); 
+0

仍然不显示。我试着把它放在之间。 – catandmouse