1 回答

TA貢獻1847條經驗 獲得超7個贊
您需要為所有評論提供一個單一的回復模式。由于您沒有指定正在使用的平臺,因此這是一種通用方法。
每個回復按鈕都應該有一個數據屬性,其中包含您要回復的評論的 ID。例如
<button class="reply-button" data-comment-id="<?php echo $comment->id; ?>">Reply</button>
或者data-comment-id如果評論將附加到帖子,而不是作為對其他評論的回復,則將該屬性留空。
如果您在單個頁面上顯示多篇博文并希望每篇文章都有自己的回復按鈕,只需添加 data 屬性post-id,如下所示:
<button class="reply-button" data-post-id="<?php echo $blog_post->id; ?>">Reply</button>
使用 JavaScript 打開評論模式并選擇適當的數據屬性。例如:
$('.reply-button').on('click', function() {
? ? const commentId = $(this).data('comment-id');
? ? const postId = $(this).data('post-id');
? ? showCommentModal(commentId, postId);
});
showCommentModal函數應該顯示頁面上的單一模式。使用commentId它postId應該準備發布評論作為對另一條評論或博客文章的回復。
- 1 回答
- 0 關注
- 340 瀏覽
添加回答
舉報