js+css实现的简单易用兼容好的分页
作者:互联网
2025-08-17
效果:
html:
复制代码代码如下:
< div id="page" >< /div >
用法:
复制代码代码如下:
var total = 310;
var pageNo = 1;
var pageCount = 31;//共有多少页
var pageSize = 10;
var actionName = "list.action";
var otherParam = "&name='www'&order='time'";
$(function(){
paginate();//分页}
);
css:
复制代码代码如下:
#page{
font-size: 14px;
clear: both;
padding-top: 1.45em;
white-space: nowrap;
}
#page a{
background: white;
border: 1px solid #E7ECF0;
display: inline-block;
height: 22px;
line-height: 22px;
margin-right: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
width: 23px;
}
#pagePre,#pageNext{
}
.pageCurrent{
font-weight: bold;
}
js:
复制代码代码如下:
function mcPaginate(){
var $pageDiv = $("#page");
actionName = actionName + "?pageSize="+pageSize;
if(typeof otherParam != 'undefined' && otherParam != ""){
actionName = actionName + otherParam;
}
$pageDiv.append("第"+pageNo+"页/共"+pageCount+"页");
//上一页
if(pageNo > 1){
var hf = actionName + "&pageNo="+(pageNo-1);
$pageDiv.append("< a href='"+hf+"' style='width: 65px;' >"+"上一页"+"< /a >");
};
if(pageCount < = pageSize){
for(var i=0; i < pageCount; i++){
var hf = actionName + "&pageNo="+(i+1);
if(pageNo == (i+1)){//当前页
$pageDiv.append("< a href='"+hf+"' class='pageCurrent' >"+pageNo+"< /a >");
}else{
$pageDiv.append("< a href='"+hf+"' >"+(i+1)+"< /a >");
};
};
}else{
for(var i=0; i < pageSize; i++){
var midIndex = 0;
if(pageSize%2 == 0){
midIndex = pageSize/2 - 1;
}else{
midIndex = pageSize/2;
}
var num = -midIndex;
var showPageNum = pageNo+i+num;
if(showPageNum > 0 && showPageNum < = pageCount){
var hf = actionName + "&pageNo="+showPageNum;
if(pageNo == showPageNum){//当前页
$pageDiv.append("< a href='"+hf+"' class='pageCurrent' >"+showPageNum+"< /a >");
}else{
$pageDiv.append("< a href='"+hf+"' >"+showPageNum+"< /a >");
};
};
};
}
//下一页
if(pageNo < pageCount){
var hf = actionName + "&pageNo="+(pageNo+1);
$pageDiv.append("< a href='"+hf+"' style='width: 65px;' >"+"下一页"+"< /a >");
};
$pageDiv.append("转到"+"< input type='text' class='goNum' style='width:30px;' name='goNum' >页< input type='button' name='goButton' class='goButton' value='确定' >");
$(".goButton").click(function(){
var goNum = $(".goNum").val();
if(goNum!=""){
window.location.href = actionName + "&pageNo="+goNum;
}
});
};
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
都知道AI大模型能生成文本内容,那你知道大模型是怎样生成文本的吗?
vue3 数据响应式遇到的问题
vxe-table 自定义数字行主键,解决默认字符串主键与后端类型不匹配问题
AI 打字跟随优化
你的 Vue 3 defineEmits(),VuReact 会编译成什么样的 React?
Vue3 + TS 企业级工程化项目全套实战(Vue3 + Vite + Pinia + VueRouter + Element Plus)
Vue 3 defineOptions 宏,用 VuReact 编译成 React 长什么样?
Vue3 KeepAlive 深度揭秘:组件缓存的魔法是如何实现的?
你的 Vue 3 useAttrs(),VuReact 会编译成什么样的 React?
虚拟 DOM 的 Diff 算法:Vue/React 如何实现高效更新
AI精选
