标题: 万能虎友,这该怎么解决啊
时间: 2023-05-08发布,2023-05-08修改
<div id="load-more-container">
{if $maxPage > 1}
<button id="load-more-btn" data-page="{$p+1}" data-max-page="{$maxPage}">加载更多</button>
{/if}
</div>
<script>
document.getElementById('load-more-btn').addEventListener('click', function() {
var page = this.getAttribute('data-page');
var maxPage = this.getAttribute('data-max-page');
if (page <= maxPage) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/q.php/bbs.{$pid}.{$tid}.' + parseInt(page) + '.json', true);
xhr.onload = function() {
// 解析 JSON 数据
var jsonData = JSON.parse(xhr.responseText);
// 获取 tContents 数组
var comments = jsonData.tContents;
// 遍历数组并生成 HTML 内容
var commentsHtml = '';
for (var i = 0; i < comments.length; i++) {
var comment = comments[i];
commentsHtml += '<div class="comment">' +
'<div class="comment-header">' +
'<div class="comment-author">' + comment.uinfo.name + '</div>' +
'<div class="comment-date">' + comment.ctime + '</div>' +
'</div>' +
'<div class="comment-body">' + comment.content + '</div>' +
'</div>';
}
// 将 HTML 内容插入到指定的 div 中
document.getElementById('myDiv').insertAdjacentHTML('beforeend', commentsHtml);
document.getElementById('load-more-btn').setAttribute('data-page', parseInt(page) + 1);
};
xhr.send();
} else {
this.disabled = true;
}
});
</script>
<div id="myDiv"></div>
『回复列表(7|显示机器人聊天)』