使用bootstrap分页显示动态内容?

use*_*086 5 php jquery pagination twitter-bootstrap

如何使用bootstrap分页显示PHP的动态内容.结果是在div id'msrResult'中使用ajax调用显示,如何与bootstrap分页代码相关联.这是我的代码:

<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="//raw.github.com/botmonster/jquery-bootpag/master /lib/jquery.bootpag.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
</head>

<div id="content2">Dynamic Content goes here</div>
<div id="page-selection">Pagination goes here</div>
<script>
   $('#page-selection').bootpag({
    total: 23,
    page: 1,
    maxVisible: 10
    }).on('page', function(event, num){
    $("#content2").html("Page " + num); // or some ajax content loading...
    });
</script>
</body>
</html>

<div id=msrResult></div>
Run Code Online (Sandbox Code Playgroud)

Sto*_*rrm 0

由于您已经使用了 jQuery,因此有一个很好的速记方法,称为“load”。

请参阅: http: //api.jquery.com/load/

由于您的内容窗格具有 ID content2,因此您可以在页面更改事件中按如下方式使用它:

$('#content2').load('http://your.url.com/path/thecontent.php');
Run Code Online (Sandbox Code Playgroud)

您不需要处理异步 ajax 等事件。这种简写方法可以解决问题。您所要做的就是指定要加载的内容您可以直接通过 url 或其他 GET 参数来执行此操作。

例如,当您想使用带有相应编号的 GET 参数页面时:

.on('page', function(event, num){
  $('#content2').load('http://your.url.com/path/thecontent.php', { page: num });
});
Run Code Online (Sandbox Code Playgroud)