2009-10-02 61 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