2009-12-30 87 views
3

我正在用Jquery UI TABS製作頁面。 在其中一個選項卡中,我想對評論進行分頁。 我想要這樣的事情。當用戶點擊頁面的編號, 鏈接的頁面的數據將通過標籤中的ajax加載。Jquery UI的Tab內容分頁

這裏是我的代碼

<script type="text/javascript"> 
$(function() { 
    $("#tabs").tabs(); 
}); 



$('#demo').tabs({ 
    load: function(event, ui) { 
     $('a', ui.panel).click(function() { 
      $(ui.panel).load(this.href); 
      return false; 
     }); 
    } 
}); 




</script> 

我怎樣才能改變這一狀況,使裏面的內容的任何關聯允許ID爲「分頁」

<a href="/coments?page=12&user_id=12" id="pagination">12</a> 

說? 由於事先

I tried recently like this even and no luck. 

這是http://www.bannerite.com/jquerytest/index2.php

這工作

<script type="text/javascript"> 
    $(function() {   
     $("#tabs").tabs(); 
     var hijax = function(panel){ 
      $('a', panel).click(function() {    
       /**makes children 'a' on panel load via ajax, hence hijax*/ 
       $(panel).load(this.href, null, function(){ 
        /**recursively apply the hijax to newly loaded panels*/ 
        hijax(panel);     
       }); 

       /**prevents propagation of click to document*/ 
       return false; 
      }); 

      $('form', panel).css({background: 'yellow'}).ajaxForm({ 
       target: panel, 
      });  
     }; 

     $('#demo ul').tabs({ 
      /**initialize the tabs hijax pattern*/ 
      load: function(tab, panel) { 
       hijax(panel); 
      } 
     }); 
    }); 
</script> 

這裏的HTML部分卡爾紅粉,但沒有更迭。當點擊測試鏈接轉到另一頁........ 當點擊

我想發佈HTML在這裏,但因爲用戶名譽較低< 10不能給HTML提供鏈接我已經發布它這裏

http://gevork.ru/2009/12/31/jquery-ui-tab-and-pagination-html/#more-58 

回答

1

它可能無法正常工作的一個原因是,#demo沒有在ready事件中被標記,而是立即改變。只要不使用底層腳本的方法,這個調用需要被移入傳入$的匿名函數中。

$(function() {  
    $('#tabs').tabs({ 
     load: function(event, ui) { 
      $('a', ui.panel).click(function() { 
       $(ui.panel).load(this.href); 
       return false; 
      }); 
     } 
    }); 
}); 

除此之外 - 不知道實際的HTML - 我不知道是否有其他錯誤。

'與ID「分頁」的任何鏈接聽起來好像有不止一個。在這種情況下:一個id必須是唯一的,所以它應該在這裏變成一個類。

+0

是啊!此代碼可以工作,但由於某種原因,它只能運行一次: - /第一次單擊後,它停止加載到同一個選項卡並打開一個新窗口。它爲什麼這樣做? – cbarg 2012-11-17 19:57:59

0

我認爲你有你的代碼錯誤,你有面板應該是ui.panel。 這對我有用。

<script type="text/javascript"> 
    $(function() { 
     var hijax = function(panel) { 
      $('a.pagination', panel).click(function(){ 
       $(panel).load(this.href, {}, function() { 
        hijax(this); 
       }); 
       return false; 
      }); 
     }; 
     $("#tabs").tabs({ 
      ajaxOptions: { 
       error: function(xhr, status, index, anchor) { 
        $(anchor.hash).html("Couldn't load this tab."); 
       }, 
      }, 
      load: function(event, ui) { 
       hijax(ui.panel); 

      } 
     }); 
    }); 
</script> 
0

我寫了一個插件來做Hijax似乎migth幫助你。 你會使用Tabs插件,所以你可能必須設置選項卡以正確顯示在CSS(我不熟悉標籤插件)。

你可以下載,看文檔和一個例子:www.yarontadmor.co.cc/hijax.php