分享一下自己在项目中引用的Jquery分页控件
index.html内容
<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>简单的jQuery分页插件下载</title>
<style>
*{ margin:; padding:; list-style:none;}
a{ text-decoration:none;}
a:hover{ text-decoration:none;}
.tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;text-align:center;}
.tcdPageCode a{display: inline-block;color: #428bca;display: inline-block;height: 25px; line-height: 25px; padding: 10px;border: 1px solid #ddd; margin: 2px;border-radius: 4px;vertical-align: middle;}
.tcdPageCode a:hover{text-decoration: none;border: 1px solid #428bca;}
.tcdPageCode span.current{display: inline-block;height: 25px;line-height: 25px;padding: 10px;margin: 2px;color: #fff;background-color: #428bca; border: 1px solid #428bca;border-radius: 4px;vertical-align: middle;}
.tcdPageCode span.disabled{ display: inline-block;height: 25px;line-height: 25px;padding: 10px;margin: 2px; color: #bfbfbf;background: #f2f2f2;border: 1px solid #bfbfbf;border-radius: 4px;vertical-align: middle;}
</style>
</head>
<body>
<br><br><br> <div class="tcdPageCode"></div> <script src="js/jquery-1.8.3.min.js"></script>
<script src="js/jquery.page.js"></script>
<script>
$(".tcdPageCode").createPage({
pageCount:,
current:,
backFn:function(p){
//console.log(p);
$("#tcdPageCode").html+="总条数:"+total;
}, });
</script> <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>
</body>
</html>
jquery.page.js中的内容
(function($){
var ms = {
init:function(obj,args){
return (function(){
ms.fillHtml(obj,args);
ms.bindEvent(obj,args);
})();
},
//填充html
fillHtml:function(obj,args){
return (function(){
obj.empty();
//上一页
if(args.current > ){
obj.append('<a href="javascript:;" class="prevPage">上一页</a>');
}else{
obj.remove('.prevPage');
obj.append('<span class="disabled">上一页</span>');
}
//中间页码
if(args.current != && args.current >= && args.pageCount != ){
obj.append('<a href="javascript:;" class="tcdNumber">'++'</a>');
}
if(args.current- > && args.current <= args.pageCount && args.pageCount > ){
obj.append('<span>...</span>');
}
var start = args.current -,end = args.current+;
if((start > && args.current < )||args.current == ){
end++;
}
if(args.current > args.pageCount- && args.current >= args.pageCount){
start--;
}
for (;start <= end; start++) {
if(start <= args.pageCount && start >= ){
if(start != args.current){
obj.append('<a href="javascript:;" class="tcdNumber">'+ start +'</a>');
}else{
obj.append('<span class="current">'+ start +'</span>');
}
}
}
if(args.current + < args.pageCount - && args.current >= && args.pageCount > ){
obj.append('<span>...</span>');
}
if(args.current != args.pageCount && args.current < args.pageCount - && args.pageCount != ){
obj.append('<a href="javascript:;" class="tcdNumber">'+args.pageCount+'</a>');
}
//下一页
if(args.current < args.pageCount){
obj.append('<a href="javascript:;" class="nextPage">下一页</a>');
}else{
obj.remove('.nextPage');
obj.append('<span class="disabled">下一页</span>');
}
})();
},
//绑定事件
bindEvent:function(obj,args){
return (function(){
obj.on("click","a.tcdNumber",function(){
var current = parseInt($(this).text());
ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current);
}
});
//上一页
obj.on("click","a.prevPage",function(){
var current = parseInt(obj.children("span.current").text());
ms.fillHtml(obj,{"current":current-,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current-);
}
});
//下一页
obj.on("click","a.nextPage",function(){
var current = parseInt(obj.children("span.current").text());
ms.fillHtml(obj,{"current":current+,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current+);
} });
})();
}
}
$.fn.createPage = function(options){
var args = $.extend({
pageCount : ,
current : ,
backFn : function(){}
},options);
ms.init(this,args);
}
})(jQuery);
项目中
function AD(s){
var postData = {TypeId:@ViewBag.keyValue,page:s };
postData = JSON.stringify(postData);
var data={queryJson:postData}; $.SetForm({
url: "../../publicinfomanage/notice/getpagelistjson",
param: data,
success: function (result) {
$("#NLS").html("");
var htmls = "";
for (var i = ; i < result.rows.length; i++) {
if (result.rows[i].FullHeadColor != undefined) {
htmls += "<li><a href='#' onclick=\"addTabs('','/publicinfomanage/notice/detail?keyvalue="+result.rows[i].NewsId+"','企业文化-"+result.rows[i].FullHead+"')'><font color='"+result.rows[i].FullHeadColor+"'>" + result.rows[i].FullHead + "</font></a><span style='float:right;'>" + result.rows[i].CreateDate.substring(,) + "</span></li>";
}else{
htmls += "<li><a href='#' onclick=\"addTabs('','/publicinfomanage/notice/detail?keyvalue="+result.rows[i].NewsId+"','企业文化-"+result.rows[i].FullHead+"')\">" + result.rows[i].FullHead + "</a><span style='float:right;'>" + result.rows[i].CreateDate.substring(,) + "</span></li>";
}
}
$("#NLS").html(htmls); }
})
} function pageCont(pc){
$(".tcdPageCode").createPage({
pageCount:pc,
current:1,
backFn:function(p){
AD(p); //p返回是当前第几页
}
});
}