javascript - Jquery Paginate 将项目放在第二页上,并且列表上没有限制,因此实际上并不分页

标签 javascript jquery pagination

查看我的 JsFiddle http://jsfiddle.net/iamdanbarrett/frbh9/

所以这是分页的内联JS......

            <script>
                        $(window).load(
function()
{
  var o=$('#paginate').first(),
      h=o.height(),
      c=$('<div/>').css('width',o.width()).addClass('part'),
      cc,i=1,item,
      p=$('<div id="pagination"></div>').append($('<a/>').text('['+1+']').data({i:0}));

      o.before(p);


  do{
      if(typeof cc=='undefined'){cc=c.clone().appendTo(o);}


    item=o.children().not('.part').first().appendTo(cc.first());

    if(cc.children().length>0 && cc.height()>=h)
    {
      p.append($('<a/>').data({i:i++}).text('['+(i)+']'));
      cc=c.clone().appendTo(o).append(item);
    }
  }while($('#paginate').first().children().not('.part').length>0);

  if($('.part',o).length<2){p.remove();return;}
  $('.part',o).not(':eq(0)').hide();
    $('a',p).click(function(){
      var _this=$(this);
      $('a',_this.parent()).removeClass('current');
      _this.addClass('current');

      $('#paginate>.part').hide().eq(_this.data('i')).show();
      }).first().addClass('current');


  return;
});
            </script>

这是列表更新的外部...

$(document).ready(function() {
    $newItemField = $('#newItem');
    $addButton = $('#add');
    $('ol').sortable();
    $('li').append('<span class="delete">x</span');
    $('ol').delegate('li','mouseover mouseout',function() {
        $(this).toggleClass('hovered');
    });
    $('ol').delegate('li>.delete','mouseover mouseout',function() {
        $(this).toggleClass('hovered');
    });
    $('ol').on('click','li>.delete',function(){
        $(this).parent().remove();
    });
    $newItemField.keypress(function(e) {
        if (e.which == 13) {
            addItem();
        }
    });
    $addButton.click(function() {
        addItem();
    });
});
function addItem() {
    if ($newItemField.val() !== '') {
        $newItem = $('<li/>');
        $newItem.text($newItemField.val());
        $deleteButton = $('<span/>').text('x').addClass('delete');
        $newItem.append($deleteButton);
        $newItem.css('background-color','#e4ffef');
        $newItem.appendTo('ol');
        $newItem.animate({backgroundColor:'#FFFFFF'},5000);
        $newItemField.val('');
    }
}

我现在有一个要通过输入更新的任务列表,并将其放入一个 OL 中,该 OL 效果很好,并且与分页一起使用效果很好,但将项目放在第二页上....

有什么想法吗?

最佳答案

这是因为 ol 元素位于 paginate div 的第二个元素内。 请参阅下文(渲染后即可看到)。

<div id="paginate">
  <div class="part" style="width: 960px;"></div>
  <div class="part" style="width: 960px; display: none;">
    <ol class="ui-sortable"></ol>
  </div>
  <div class="part" style="width: 960px; display: none;"></div>
</div>

因此,放置下面的代码将达到预期效果并按预期工作。

$(".ui-sortable").appendTo("#paginate div:first-child");

现在正在运行... http://jsfiddle.net/iashu/Nty7M/

关于javascript - Jquery Paginate 将项目放在第二页上,并且列表上没有限制,因此实际上并不分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21883637/

相关文章:

javascript - QuickPager Javascript 适用于一次单击,但不适用于第二次单击

php - 如果 laravel 中只有一页,则隐藏分页链接

javascript - AJAX 调用后 PHP 没有返回响应

javascript - RxJs:组合两个可观察量 - 从第一个观察到的所有,但不是从第二个观察到的全部

javascript - 在页面的多个部分输出

jquery - 如何覆盖 jQuery 中的 !important CSS 属性

javascript - 如何在 Kendo Scheduler 上正确设置最大高度?

Javascript 引用正则表达式匹配

javascript - 是否有用于将字符串编码为 HTML 的内置 jQuery 函数?

javascript - 有没有办法更改 Material 表(reactjs)中的默认页面索引(0)