如何在分页引导程序中添加当前活动状态?
我的代码
...
<?php for ($page=1; $page <= $total_pages ; $page++):?>
<li class="page-item">
<a href='<?php echo "?page=$page"; ?>' class="links"><?php echo $page; ?></a>
</li>
<?php endfor; ?>
...
答案 0 :(得分:0)
将课程active
添加到li
。
示例
<ul class="pagination">
<li><a href="#">1</a></li>
<li class="active"><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
答案 1 :(得分:0)
<script>
var url = window.location;
// Will only work if string in href matches with location
$('ul.pagination a[href="'+ url +'"]').parent().addClass('active');
// Will also work for relative and absolute hrefs
$('ul.pagination a').filter(function() {
return this.href == url;
}).parent().addClass('active');
</script>