如何使用 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>
最佳答案
因为您已经在使用 jQuery,所以有一个名为“load”的简写方法。
参见:http://api.jquery.com/load/
因为您的内容 Pane 具有 ID content2,您可以在页面更改事件中按如下方式使用它:
$('#content2').load('http://your.url.com/path/thecontent.php');
您不需要处理异步 ajax 等事件。这种简写方法可以解决问题。您所要做的就是指定要加载的内容。您可以直接通过 url 或通过其他 GET 参数执行此操作。
例如,当你想使用相应编号的 GET 参数页面时:
.on('page', function(event, num){
$('#content2').load('http://your.url.com/path/thecontent.php', { page: num });
});
关于php - 使用 Bootstrap 分页显示动态内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25139127/