我正在嘗試打開與帖子相關的特定評論,但是當我點擊查看更多評論時,所有評論都在打開,但我想打開與帖子相關的評論,但并非所有評論都請幫助我如何解決這個問題?感謝你
html視圖
<div class="comment-box">
@foreach ($communityPosts->communityPostReply as $communityPostReplies)
<div class="user-comment-box">
<div class="d-flex pt-3">
<div class="notification-text ms-3 w-100">
<span class="username fw-bold">{{$communityPostReplies->users->full_name}}</span>
<p class="mt-2 mb-0">{{$communityPostReplies->reply_body}}</p>
<span class="text-muted small">{{$communityPostReplies->created_at->diffForHumans()}}</span>
</div>
</div>
</div>
@endforeach
<a style="cursor: pointer;" class="see-more">View More Comments</a>
這是我的jQuery
$(function(){
$(".user-comment-box").slice(-5).show(); // select the first 5 hidden divs
$(".see-more").click(function(e){ // click event for load more
e.preventDefault();
var done = $('<div ></div>');
$(".user-comment-box:hidden").slice(-5).show(); // select next 5 hidden divs and show them
if($(".user-comment-box:hidden").length == 0){ // check if any hidden divs
$(".see-more").replaceWith(done); // if there are none left
}
});
});
uj5u.com熱心網友回復:
您應該將選擇器限制為僅當前.comment-boxdiv。
$(function() {
$(".user-comment-box").slice(-5).show(); // select the first 5 hidden divs
$(".see-more").click(function(e) { // click event for load more
e.preventDefault();
let current_post = $(this).closest(".comment-box");
var done = $('<div ></div>');
current_post.find(".user-comment-box:hidden").slice(-5).show(); // select next 5 hidden divs and show them
if (current_post.find(".user-comment-box:hidden").length == 0) { // check if any hidden divs
$(this).replaceWith(done);
}
});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478985.html
標籤:jQuery
下一篇:頁面加載后獲取URL引數
