generated from dellevin/template
修复bug
This commit is contained in:
@@ -924,7 +924,7 @@
|
||||
/* 加载更多按钮样式(用于留言板等实心弹窗) */
|
||||
.load-more-btn {
|
||||
display: block;
|
||||
margin: 20px auto;
|
||||
margin: 20px auto 50px auto;
|
||||
background: #fff;
|
||||
border: 1px solid #e8e8e8;
|
||||
color: #666;
|
||||
@@ -945,7 +945,7 @@
|
||||
/* 加载完成提示 */
|
||||
.load-complete {
|
||||
text-align: center;
|
||||
padding: 20px 25px;
|
||||
padding: 20px 25px 50px 25px;
|
||||
color: #bbb;
|
||||
font-size: 13px;
|
||||
font-style: italic;
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
});
|
||||
html += '</div>';
|
||||
|
||||
// 只有在还有更多数据时才显示加载更多按钮
|
||||
if (hasMore) {
|
||||
html += `<button class="load-more-btn" onclick="window.loadMoreBlogPosts()">点击加载更多</button>`;
|
||||
} else {
|
||||
@@ -142,8 +143,6 @@
|
||||
// 追加文章
|
||||
function appendPosts(posts) {
|
||||
const containers = document.querySelectorAll('.blog-posts-container');
|
||||
const loadMoreBtns = document.querySelectorAll('.load-more-btn');
|
||||
const oldTips = document.querySelectorAll('.load-complete');
|
||||
|
||||
if (containers.length === 0) {
|
||||
console.error('未找到 .blog-posts-container 容器');
|
||||
@@ -157,29 +156,29 @@
|
||||
div.innerHTML = renderPostItem(post);
|
||||
container.appendChild(div.firstElementChild);
|
||||
});
|
||||
});
|
||||
|
||||
// 移除所有旧的加载更多按钮和提示
|
||||
loadMoreBtns.forEach(btn => btn.remove());
|
||||
oldTips.forEach(tip => tip.remove());
|
||||
// 移除当前容器后的旧按钮和提示(只操作当前容器的兄弟元素)
|
||||
let nextSibling = container.nextElementSibling;
|
||||
while (nextSibling && (nextSibling.classList.contains('load-more-btn') || nextSibling.classList.contains('load-complete'))) {
|
||||
const toRemove = nextSibling;
|
||||
nextSibling = nextSibling.nextElementSibling;
|
||||
toRemove.remove();
|
||||
}
|
||||
|
||||
// 向所有容器后添加新的加载更多按钮或提示
|
||||
if (hasMore) {
|
||||
containers.forEach(container => {
|
||||
// 在当前容器后添加新的加载更多按钮或提示
|
||||
if (hasMore) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'load-more-btn';
|
||||
btn.textContent = '点击加载更多';
|
||||
btn.onclick = window.loadMoreBlogPosts;
|
||||
container.after(btn);
|
||||
});
|
||||
} else {
|
||||
containers.forEach(container => {
|
||||
} else {
|
||||
const tip = document.createElement('div');
|
||||
tip.className = 'load-complete';
|
||||
tip.textContent = '已显示全部';
|
||||
container.after(tip);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`成功追加 ${posts.length} 篇文章到 ${containers.length} 个容器,当前页码: ${currentPage}`);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
guestbookBody.innerHTML = '<div class="guestbook-loading" data-i18n="guestbook_loading">正在加载留言...</div>';
|
||||
} else {
|
||||
// 添加加载更多按钮状态
|
||||
const loadMoreBtn = document.querySelector('.load-more-btn');
|
||||
const loadMoreBtn = guestbookBody.querySelector('.load-more-btn');
|
||||
if (loadMoreBtn) {
|
||||
loadMoreBtn.disabled = true;
|
||||
loadMoreBtn.textContent = '加载中...';
|
||||
@@ -196,9 +196,8 @@
|
||||
// 判断是否还有更多数据
|
||||
if (hasMore) {
|
||||
html += `<button class="load-more-btn" onclick="window.loadMoreGuestbook()">点击加载更多</button>`;
|
||||
} else {
|
||||
html += `<div class="load-complete">已显示全部</div>`;
|
||||
}
|
||||
// 否则不显示任何内容
|
||||
|
||||
guestbookBody.innerHTML = html;
|
||||
|
||||
@@ -271,9 +270,8 @@
|
||||
|
||||
// 追加留言
|
||||
function appendGuestbook(comments) {
|
||||
const listContainer = document.querySelector('.guestbook-list');
|
||||
const loadMoreBtn = document.querySelector('.load-more-btn');
|
||||
const allDataTip = document.querySelector('.guestbook-body > div:last-child');
|
||||
const listContainer = guestbookBody.querySelector('.guestbook-list');
|
||||
const loadMoreBtn = guestbookBody.querySelector('.load-more-btn');
|
||||
|
||||
if (!listContainer) return;
|
||||
|
||||
@@ -283,16 +281,12 @@
|
||||
listContainer.appendChild(div.firstElementChild);
|
||||
});
|
||||
|
||||
// 移除旧的加载更多按钮和提示
|
||||
// 移除旧的加载更多按钮
|
||||
if (loadMoreBtn) {
|
||||
loadMoreBtn.remove();
|
||||
}
|
||||
const oldTip = document.querySelector('.load-complete');
|
||||
if (oldTip) {
|
||||
oldTip.remove();
|
||||
}
|
||||
|
||||
// 如果还有更多,添加新的加载更多按钮
|
||||
// 如果还有更多,添加新的加载更多按钮;否则显示"已显示全部"
|
||||
if (hasMore) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'load-more-btn';
|
||||
@@ -300,7 +294,6 @@
|
||||
btn.onclick = window.loadMoreGuestbook;
|
||||
listContainer.after(btn);
|
||||
} else {
|
||||
// 没有更多数据,显示提示
|
||||
const tip = document.createElement('div');
|
||||
tip.className = 'load-complete';
|
||||
tip.textContent = '已显示全部';
|
||||
|
||||
Reference in New Issue
Block a user