jquery 分页控件的位置显示。求救!!!

发布网友 发布时间:2022-04-23 17:30

我来回答

1个回答

热心网友 时间:2022-05-15 12:33

1、在class="page"的table后面加<div class="pagediv"></div>

2、.appendTo($pager);修改为.appendTo(".pagediv");


完整代码:

<table width="100%" border="1" cellspacing="0" cellpadding="0" class="page">
  <tr>
    <th scope="col">&nbsp;</th>
    <th scope="col">&nbsp;</th>
    <th scope="col">&nbsp;</th>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<div class="pagediv"></div>
<script type="text/javascript">
$(function () {
            $('table.page').each(function () {

                var currentPage = 0;
                var numPerPage = 6;
                var $table = $(this);

                var pageFunction = function () {
                    $table.find('tbody tr').show()
    .slice(0, currentPage * numPerPage)
    .hide()
    .end()
    .slice(((currentPage + 1) * numPerPage - 1) + 1)
    .hide()
    .end();
                } //end of   pageFunction()
                var num_row = $table.find('tbody tr').length;
                var num_pages = Math.ceil(num_row / numPerPage);
                var $pager = $('<div></div>');
                for (var i = 0; i < num_pages; i++) {
                    $('<span> 第' + (i + 1) + '页 </span>')
      .bind("click", { 'cssrain': i }, function (event) {
          currentPage = event.data['cssrain'];
          pageFunction();
          $(this).addClass('current').siblings().removeClass('current');
      })
     .appendTo(".pagediv");
                }

                $pager.insertBefore($table);
                $pager.find("span:first").addClass('current');
                pageFunction();
            })//end of each()
        })//enf of function
</script>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com