如何从一个页面自动移动到另一个页面并返回到html中的表格中存在分页的第一页

时间:2016-04-22 13:30:02

标签: javascript jquery html pagination

我正在尝试使用HTML中的表格添加分页自动转发功能。 例如,我有100行的表,然后我在一页上有10个记录的分页。所以将有10页,每页10条记录。 我需要自动执行此操作,以便用户无需专门点击该页面即可查看。

我使用了paging.js

以下代码

  <style type="text/css">
  .paging-nav {
  text-align: right;
  padding-top: 2px;
  }
  .paging-nav a {
  margin: auto 1px;
  text-decoration: none;
  display: inline-block;
  padding: 1px 7px;
  background: #91b9e6;
  color: white;
  border-radius: 3px;
  }
  .paging-nav .selected-page {
  background: #187ed5;
  font-weight: bold;
  }
  .paging-nav,
  #tableData {
  'width: 400px;
  margin: 0 auto;
  font-family: Arial, sans-serif;
  }
  </style>

  $(document).ready(function() {
  $('#file').paging({limit:10});
  });

这里的文件是要分页的表的id。如何自动更改表格页面?欢迎所有答案。

1 个答案:

答案 0 :(得分:0)

这是一个如何开始的例子.. 要注意这只是一个例子,不要复制!为了您自己的保护

&#13;
&#13;
//create
el = $("<table></table>");
for (var i = 1; i !== 100; i++) {
  el.append("<tr><td>" + i + "</td><td>buuurp</td></tr>");
}
el.data("intStart", 1);
el.appendTo("body");


//fuction
function showRow(j = 10) { //default var j = 10; you can call showRow(50) for 50 as example
  var i = $("table").data().intStart; //grabs data that hold the number of currect first element to view
  $("tr").hide();
  // hides all
  $("tr").filter(function(index) {
    return index >= i - 1 && index < i + j - 1; //jquery has 0-9 we count in 1-10 so -1
  }).show(); //shows the one needed
  $("table").data().intStart += j; //addes 'j' to the counter
  if ($("table").data().intStart > $("table").children("tr").lenght) {
    clearInterval(timer); //if we reach the end we can kill this
  }
}

showRow();
var timer = setInterval(function() {
  showRow();
}, 3000);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;