doubiantiao4994 2010-11-30 14:57
浏览 53
已采纳

删除/添加分页按钮

I have a blog.Few articles inside.Per each article I have a lot of comments that I decide to paginate in group of 5 (let's say..if i have 15 comments i have 3 pagination buttons).
I did this by a method of my comment_manager class on pageLoad.

public function pagination($in_art,$perPage)
{
    $per_page=$perPage;
    $count=$this->countComments($in_art);
    $pages = ceil($count/$per_page);

    if($count>=$perPage)
    {
    echo"<div class='pagination'>";
         for($i=1; $i<=$pages; $i++)
        {
            echo "<div class='pag' id='pag_{$i}'>$i</div>";
        }
    echo"</div>";
    }
}

everything is fine.
This is how I handle my buttons through JQuery

$(document).ready(function()
{
  [...]//code missing for sake of brevity

  $('#pag_1').css({'color' : '#FF0084'}).css({'border' : 'none'});

  //Pagination Click
  $(".pag").click(function(){

  //CSS Styles
  $(".pag")
  .css({'border' : 'solid #dddddd 1px'})
  .css({'color' : '#0063DC'});

 $(this)
 .css({'color' : '#FF0084'})
 .css({'border' : 'none'});

 //Loading Data
 var data="page="+pageNum+"&id_art="+idArt;
 $.ajax({  
        type: "POST",  
        url: "php/pagination_data.php",  
        data: data,  
        cache: false,  
        success: function(html){  
                                 $('#comments_'+idArt).html(html);  
                               }                                                                        
       });

  });

The point is I need to refresh my pagination buttons after deleting or adding new comments on the fly (dont want the whole page to refresh!).So remove them or add new ones if needed(for example with 16 comments i need one more button) Thanks
Luca

  • 写回答

1条回答 默认 最新

  • dongranding3909 2010-12-06 23:34
    关注

    Seems to me that if you want the actual pagination links to be updated on the fly, then you will need to create an AJAX version that returns the current pagination.

    For example: When you delete a comment, after the comment gets deleted, run an AJAX call to get what the pagination is now, and update the pagination div's contents.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条