时间:2021-07-01 10:21:17 帮助过:6人阅读
思路:
主要是初始化时基于原型建立的分页模板然后绑定动态事件并实现刷新DOM的分页效果。
1.page.init.css
@charset "utf=8";
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
.page{
font-size: 13px;
text-align: right;
}
.page .page_to{
display: inline-block;
max-width: 250px;
}
.page .page_to li{
display: inline-block;
width: auto;
height: auto;
border: 1px solid #ddd;
padding:5px 10px;
border-left-width: 0;
color: #323232;
cursor: pointer;
}
.page .page_to li.page_hide{
display: none;
}
.page .page_to li:hover{
color: #32C2CD;
background-color: #f4f4f4;
border-color: #DDDDDD;
}
.page .page_to li:first-child{
border-left-width: 1px;
}
.page .page_jump{
display: inline-block;
width: 180px;
}
.page .page_jump input.page_jump_input{
width: 52px;
height: 28px;
text-align: center;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
margin:0 4px;
}
.page .page_jump input.page_jump_btn{
display: inline-block;
padding: 7px 20px;
margin-left: 5px;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
border-radius: 4px;
background-color: #00BB9C;
color: #FFFFFF;
font-weight: bold;
}2.pageInit.js
3.组件调用
通过 window.pageInit= $.pageInit=pageInit 可完成分页组件初始化。
暴露出来的接口分别为:
1.container:DOM的容器,默认.page
2.setPos:DOM放置的HTML位置,默认body
3.totalPages:默认的页数,必填,默认null
4.totalLists:默认的数据总数,必填,默认null
5.initPage:当前页,默认第一页
6.inputVal:跳转页,默认第一页
7.callBack:执行的回调函数,必填,默认null
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>基于jQuery封装的分页组件</title>
<link rel="stylesheet" href="css/page.init.css">
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script src="js/pageInit.js"></script>
<script>
$.pageInit(
{
container:'.page',//容器:默认page
//setPos:'body',//放置位置:默认body
totalPages:10,//总页数:必填
totalLists:100,//数据总数:必填
initPage:1,//初始页码:默认1
inputVal:1,//设置跳转的input值:默认1
//要执行的函数:默认null,必须为fn且返回true则可执行分页,false则不执行
callBack:function(n){
var flag=true;
console.log(n);
return flag;
}
}
);
</script>
</body>
</html>效果:
通过callBack接口,添加自己所需要执行的function函数,并且需要return true时才回执行动态的DOM渲染。

更多精彩内容请点击:jquery分页功能汇总进行学习。
相关推荐:
jQuery封装placeholder的实例代码
基于jquery封装的一个js分页_jquery
jquery封装的对话框简单实现_jquery
以上就是jQuery封装的分页组件详解的详细内容,更多请关注Gxl网其它相关文章!