2016-04-22 41 views
0

我想添加与HTML分页表的汽车。 对于例如我有100行的表,然后我正在为它分页10个记录在一页上。因此,将有10页,每个10记录。 我nedd自动做到这一点,使用户不必特意点击该页面,看看。如何做从一个页面automoving到另一个页面,并返回到第一页分页是在那里在html表

我用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将被分页。我怎样才能自动更改表格的页面?欢迎所有的答案。

回答

0

下面是一个如何开始它的例子.. 要小心这只是一个例子,不要复制!为保护你自己

//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);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

感谢我有一些想法如何做到这一点 –

相关问题