删除/添加分页按钮

发布于 2024-10-05 04:34:28 字数 1489 浏览 1 评论 0原文

我有一个博客。里面的文章很少。每篇文章我都有很多评论,我决定以 5 组为一组进行分页(假设..如果我有 15 条评论,我有 3 个分页按钮)。
我通过 pageLoad 上的 comment_manager 类的方法完成了此操作。

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>";
    }
}

一切都很好。
这就是我通过 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);  
                               }                                                                        
       });

  });

重点是我需要在动态删除或添加新注释后刷新分页按钮(不希望刷新整个页面!)。因此,如果需要,请删除它们或添加新的按钮(对于例如有 16 条评论,我还需要一个按钮) 谢谢
卢卡

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带上头具痛哭 2024-10-12 04:34:28

在我看来,如果您希望实时更新实际的分页链接,那么您将需要创建一个返回当前分页的 AJAX 版本。

例如:
当您删除评论时,在评论被删除后,运行 AJAX 调用以获取现在的分页,并更新分页 div 的内容。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文