php - 使用 Bootstrap 分页显示动态内容?

标签 php jquery twitter-bootstrap pagination

如何使用 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/

相关文章:

PHP foreach重复循环问题

php - 如何在 CodeIgniter 中扩展一个助手?

php - 如何通过 javascript 或 jquery 交换单击时选中的单选按钮???附上我的代码

Javascript/jQuery/CSS。如何在目标 div 之外维护拖动事件?

javascript - Angular Bootstrap 单选按钮不触发功能

php - 在具有多个值的字符串中搜索 Symfony 3

javascript - jQuery,将我的 jquery 代码移动到外部文件时出现引用错误

javascript - 将类添加到返回意外结果的元素

css - 如何在自己的 CSS 中使用很棒的字体?

javascript - 无法将此主题与 preg_match 匹配