<html lang="">
<head>
<link rel="stylesheet" type="text/css" href="./css/elementUiIndex.css" />
<link rel="stylesheet" type="text/css" href="./css/index.css" />
<title>
javascript写一个页码器,包括切换页码、分页、上一页/下一页、省略页码等功能
</title>
<script src="./page.js"></script>
</head>
<body>
<div class="container">
<div class="title">执行结果</div>
<div class="search-result">
<div class="table-content-fixed">
<table cellspacing="0">
<thead>
<tr>
<th width="125px">姓名</th>
<th width="125px">年龄</th>
<th width="125px">学号</th>
<th width="125px">地址</th>
<th width="125px">成绩</th>
</tr>
</thead>
</table>
</div>
<div class="table-content-scroll">
<table cellspacing="0">
<tbody></tbody>
</table>
</div>
</div>
<div
role="pagination"
aria-label="pagination"
class="el-pagination pagination hort-box"
data-v-b770da44=""
>
<span class="el-pagination__total"></span>
<button
type="button"
class="btn-prev"
onclick="handlePageChange('prev')"
>
<i class="el-icon el-icon-arrow-left"></i>
</button>
<ul class="el-pager"></ul>
<button
type="button"
class="btn-next"
onclick="handlePageChange('next')"
>
<i class="el-icon el-icon-arrow-right"></i>
</button>
</div>
</div>
</body>
<script>
let currentPage = 1;
let pageCount = 8;
let rowCount = 78;
// 获取运行数据
function getRunData() {
// 处理滚动条引起的宽度 默认无滚动条
document.getElementsByClassName("table-content-fixed")[0].style = "";
// 获取数据
let runDataList = [
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
{
name: "张三",
age: "18",
studentNo: "01",
address: "",
point: "98",
},
];
// 处理滚动条引起的宽度 长度大于9出现滚动条
if (runDataList.length > 9) {
document.getElementsByClassName("table-content-fixed")[0].style =
"width:calc(100% - 8px)";
}
// 清空执行结果
let tbody = document.getElementsByTagName("tbody")[0];
tbody.innerHTML = "";
// 挂载执行结果
runDataList.forEach((item, index) => {
let tr = document.createElement("tr");
for (let key in item) {
let td = document.createElement("td");
td.width = "125px";
td.innerHTML = item[key];
tr.appendChild(td);
}
tbody.append(tr);
});
}
// 初始化页码
function initPage() {
setPage(
pageCount,
rowCount,
"container",
function (newPageObj) {
receivePageCallBack(newPageObj);
}
);
}
// 页码器跳转
function handlePageChange(val) {
let numberDomLists = document.getElementsByClassName("number");
if (val === "prev") {
currentPage--;
if (currentPage > 1) {
if (numberDomLists[1].innerText > currentPage) {
linkPrevPage(
document.getElementsByClassName("btn-quickprev")[0],
numberDomLists,
pageCount,
document.getElementsByClassName("container")[0],
function (newPageObj) {
receivePageCallBack(newPageObj);
}
);
}
}
} else if (val === "next") {
currentPage++;
if (currentPage < pageCount) {
if (
numberDomLists[numberDomLists.length - 2].innerText < currentPage
) {
linkNextPage(
document.getElementsByClassName("btn-quicknext")[0],
numberDomLists,
pageCount,
document.getElementsByClassName("container")[0],
function (newPageObj) {
receivePageCallBack(newPageObj);
}
);
}
}
}
let targetPage = getElementsByAttr(
"container",
"number",
"key",
currentPage
);
targetPage[0] && targetPage[0].onclick();
}
// 页码器回调
function receivePageCallBack(newPageObj) {
currentPage = newPageObj.newPage;
if (!newPageObj.flag) {
document
.getElementsByClassName("btn-prev")[0]
.removeAttribute("disabled");
document
.getElementsByClassName("btn-next")[0]
.removeAttribute("disabled");
if (currentPage == pageCount) {
selectLastPage(
pageCount,
"container",
function (newPageObj2) {
receivePageCallBack(newPageObj2);
}
);
} else if (currentPage == 1) {
initPage();
}
getRunData();
console.log(currentPage);
} else {
let numberDomLists = document.getElementsByClassName("number");
numberDomLists[numberDomLists.length - 2].onclick();
}
}
function run() {
getRunData();
initPage();
}
window.onload = function () {
run();
};
</script>
</html>
javascript写一个页码器,包括切换页码、分页、上一页/下一页、省略页码等功能
需积分: 0 13 浏览量
更新于2023-02-23
收藏 137KB ZIP 举报
当表格数据太多时,通常需要做成分页。本资源使用javascript实现了一个页码器,满足常规要求:切换页码、分页、上一页/下一页、页码超出时显示省略号,点击省略号往前/后显示几个隐藏的页码,使用方法见https://blog.csdn.net/sxww_zyt/article/details/129155819
Zoie_ting
- 粉丝: 1939
- 资源: 2
最新资源
- 基于数值积分和摄动方法的建筑装饰金箔使用量计算-Mathematica
- matlab:双或三方演化博弈,lotka-Volterra 1.双方演化博弈:代分析稳定点分析,代绘制相位图,matlab仿真图代码 2.三方演化博弈:代分析稳定点分析,代绘制相位图,matlab仿
- 基于模型预测控制(mpc)的车辆道,车辆轨迹跟踪,道轨迹为五次多项式,matlab与carsim联防控制
- SQL Server数据库实验:表的插入、修改和删除操作实践
- 2011-2020年各省城镇单位就业人员数据.xlsx
- Java windows GUI 案例 简单的飞机售票系统 课程设计
- 基于模型预测控制的楼宇负荷需求响应研究 参考文档:《Model Predictive Control of Thermal Storage for Demand Response》完全复现 主要内容:
- eclipse-sts-2021-03-R-win32-x86-64.rar
- Python的Mongodb操作代码
- 光伏电池PV建模,基于Boost Buck电路实现最大功率追踪MPPT,包括扰动观察法,电导增量法,改进型电导增量法,滑模变结构法等控制算法,模型仿真效果较好,适合借鉴学习 图片为模型图,功率波形
- 交直流混合微网程序matlab 采用拉丁超立方抽样和多场景缩减,考虑风光等随机性建模,利用粒子群算法,计算得到三个微网的优化程序,程序运行稳定,有详细资料 这段代码是一个多目标优化算法的实现,主要用
- 云链客服需要注意的事项
- Microsoft Edge111
- 云链客服需要注意的事项
- 三相桥式两电平逆变器的SVPWM调制和三相T型三电平逆变器的SVPWM模型和说明文档 对比着看绝对有助于你理解SVPWM调制方法 支持MATLAB2017b以上的版本
- mongodb-windows-x86-64-7.0.15-signed.msi