2009-10-02 30 views
0

我正在努力學習jQuery與「從包裝學習Jquery 1.3書」。jquery分頁

我正在關注這封信的代碼,但我發現很難讓代碼正常工作。

我正在嘗試使用下面的代碼進行簡單的頁面分頁,但我沒有運氣,任何人都可以告訴我爲什麼,並提供一些建議。

謝謝。

$(document) .ready(function() { 
    $('table.paginated').each(function() { 
     var currentPage = 0; 
     var numberPage = 5; 
     var $table = $(this); 
     $table.find('thead tr').hide() 
      .slice(currentPage * numPerPage, (currentPage + 1) * numPerPage) 
      .show(); 
    }); 
}); 

我的表選項卡:

<table id="tablesorter" class="tablesorter" border="0" cellpadding="0" cellspacing="1"> 
     <thead> 
     <tr> 
      <th>Ref</th> 
      <th>Date</th> 
      <th>Company</th> 
      <th>Operator</th> 
      <th>Boxes</th> 
      <th>Network</th> 
      <th>Quote Accept</th> 
      <th>Term Accept</th> 
      <th>Credit Check</th> 
      <th>Expiry</th> 
     </tr> 
     </thead> 
     <tbody> 

回答

2

這看起來很明顯,但是您是否加載了tablesorter和tablesorter分頁器插件?

<script type="text/javascript" src="/path/to/jquery.tablesorter.min.js"></script> 
<script type="text/javascript" src="/path/to/jquery.tablesorter.pager.js"></script> 

還是你不使用這些插件?我只是假定你是來自桌面ID。

+0

我不是沒有,你認爲那問題 – 2009-10-02 14:23:03

+0

@ OliverBayes - 謝爾頓那麼,如果在需要的時候,那麼我會說這還不包括他們來說是一個很大的問題。 ;-) – 2014-04-04 10:50:11

0

請問您的表絕對有正確的定義......即

<table> 
    <tbody> 
     <tr>...</tr> 
     <tr>...</tr> 
     <tr>...</tr> 
     <tr>...</tr> 
    </tbody> 
</table> 

,在我彈出唯一的問題是它依賴在嵌套在tbody標籤中的行上。

+0

剛編輯我的問題與 – 2009-10-02 13:54:40

+0

你是否也會分類是錯誤的語法問題,我的表標籤? – jakeisonline 2009-10-02 14:12:21

1

第一行

$(document) .ready(function() { // Bad Syntax 

刪除空間!

$(document).ready(function() { // Good Syntax