70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
let currentPage = 1;
|
|
let totalPages = 0;
|
|
let itemsPerPage = 0;
|
|
|
|
window.onload = function() {
|
|
totalPages = parseInt(prompt("请输入要创建的页面数量:", "3"));
|
|
itemsPerPage = parseInt(prompt("请输入每页的栏目数:", "4"));
|
|
|
|
generatePages();
|
|
showPage(1);
|
|
updatePageIndicator();
|
|
}
|
|
|
|
function generatePages() {
|
|
const container = document.getElementById('pagesContainer');
|
|
|
|
for(let i = 0; i < totalPages; i++) {
|
|
const page = document.createElement('div');
|
|
page.className = 'page';
|
|
page.id = `page${i+1}`;
|
|
|
|
// 添加页面标题
|
|
const title = document.createElement('h2');
|
|
title.className = 'page-title';
|
|
title.innerHTML = `第 ${i+1} 页`;
|
|
page.appendChild(title);
|
|
|
|
const contentContainer = document.createElement('div');
|
|
contentContainer.className = 'content-container';
|
|
|
|
for(let j = 0; j < itemsPerPage; j++) {
|
|
const item = document.createElement('div');
|
|
item.className = 'content-item';
|
|
item.innerHTML = `内容 ${j+1}`;
|
|
contentContainer.appendChild(item);
|
|
}
|
|
|
|
page.appendChild(contentContainer);
|
|
container.appendChild(page);
|
|
}
|
|
}
|
|
|
|
function showPage(pageNum) {
|
|
document.querySelectorAll('.page').forEach(page => {
|
|
page.classList.remove('active');
|
|
});
|
|
|
|
document.getElementById(`page${pageNum}`).classList.add('active');
|
|
}
|
|
|
|
function nextPage() {
|
|
if(currentPage < totalPages) {
|
|
currentPage++;
|
|
showPage(currentPage);
|
|
updatePageIndicator();
|
|
}
|
|
}
|
|
|
|
function prevPage() {
|
|
if(currentPage > 1) {
|
|
currentPage--;
|
|
showPage(currentPage);
|
|
updatePageIndicator();
|
|
}
|
|
}
|
|
|
|
function updatePageIndicator() {
|
|
document.getElementById('pageIndicator').textContent =
|
|
`${currentPage} / ${totalPages}`;
|
|
} |