2017-06-28 96 views
0

如何在分頁引導中添加當前活動狀態?如何在分頁引導中添加當前活動狀態

我的代碼

... 
<?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

添加類activeli

<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> 
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> 
相關問題