博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
模板分页封装
阅读量:5964 次
发布时间:2019-06-19

本文共 7707 字,大约阅读时间需要 25 分钟。

hot3.png

模板分页封装 博客分类: js
var ajaxCommFunPage = function(url, data, callback) {	jQuery.ajax({		type : "post",		async: false,		//dataType:'html',		url : url,		timeout: 30000,		data : data,		success : callback	});};var asyncSubmit = function(formId){	var formObj = $('#'+formId);	var asyncFlag = formObj.find("input[name='asyncFlag']").val();	var prefix = formObj.find("input[name='alias']").val();	var replaceId = formObj.find("input[name='replaceId']").val();			$('#currentPageHid_'+prefix).val(1);	if(asyncFlag=='true'){		var url = getContextPath() + formObj.attr('action');		ajaxCommFunPage(url, formObj.serialize(), function(str){				var ss = $(str).find('#'+replaceId).html();				$('#'+replaceId).html(ss);			});	}else{		formObj.submit();	}};var search = function(json,currentPage, pageSize) {	var formId = json["formId"];	var asyncFlag  = json["asyncFlag"];	var prefix  = json["prefix"];	var replaceId = json["replaceId"];	if(replaceId == null){		replaceId = json["formId"];	}		$('#currentPageHid_'+prefix).val(currentPage);	$('#pageSizeHid_'+prefix).val(pageSize);		var  formObj = $("#"+formId);		var url = getContextPath() + formObj.attr('action');	if(asyncFlag){		ajaxCommFunPage(url, formObj.serialize(), function(str){			var ss = $(str).find('#'+replaceId).html();			$("#"+replaceId).html(ss);		});	}else{		formObj.submit();	}};function initPageTab(json){		initBaicPageByFM(json);};var initBaicPageByFM=function (json){	var formId = json["formId"];//form表单的Id	var divId = json["divId"];//form表单内分页标签的DIVId	var asyncFlag  = json["asyncFlag"];//刷新,无刷新标志 	var prefix = json["prefix"];//分页标签的标志	var currentPage = json["currentPage"];//当前页	var totalPage = json["totalPage"];//一共多少页	var count = json["count"];//总数	var pageSize = json["pageSize"];//每页多少条	var replaceId = json["replaceId"];//需要替换的ID	if(replaceId == null){		replaceId = json["formId"];	}		    	//初始化页面    var str = $('#'+divId).html();    str = str.replace(/currentPageAlias/g,currentPage);    str = str.replace(/totalPageAlias/g,totalPage);    str = str.replace(/countAlias/g,count);    str = str.replace(/pageSizeAlias/g,pageSize);    str = str.replace(/asyncFlagAlias/g,asyncFlag);    str = str.replace(/aliasAlias/g,prefix);    str = str.replace(/replaceIdAlias/g,replaceId);    str = str.replace(/prefix/g,prefix);        var pageDiv = $('#'+divId);    pageDiv.html(str);	var pageStr = getPageSrc(currentPage,pageSize,totalPage,count);			//设置页面	$('#pagingitem_'+prefix).html(pageStr);	//设置总数 	$('#totalpage_'+prefix).html(count);		pageDiv.find('[tag=paging-action]').click(function() {		search(json,std.oid(this),pageSize);	});		pageDiv.find('#gotoNo_'+prefix).delegate(this,'click',function() {		goToCurrPageBtn(json,pageSize,totalPage,'pageNo');	});		pageDiv.find('#pageNo_'+prefix).delegate(this,'keypress',function(e) {		if (e && e.keyCode == 13) {			goToCurrPageBtn(json,pageSize,totalPage,'pageNo');		}	});};var initBaicPage=function (json){	var formId = json["formId"];//form表单的Id	var divId = json["divId"];//form表单内分页标签的DIVId	var asyncFlag  = json["asyncFlag"];//刷新,无刷新标志 	var prefix = json["prefix"];//分页标签的标志	var currentPage = json["currentPage"];//当前页	var totalPage = json["totalPage"];//一共多少页	var count = json["count"];//总数	var pageSize = json["pageSize"];//每页多少条	var replaceId = json["replaceId"];//需要替换的ID	if(replaceId == null){		replaceId = json["formId"];	}		    	//初始化页面    var str = $('#'+divId).html();    str = str.replace(/currentPageAlias/g,currentPage);    str = str.replace(/totalPageAlias/g,totalPage);    str = str.replace(/countAlias/g,count);    str = str.replace(/pageSizeAlias/g,pageSize);    str = str.replace(/asyncFlagAlias/g,asyncFlag);    str = str.replace(/aliasAlias/g,prefix);    str = str.replace(/replaceIdAlias/g,replaceId);    str = str.replace(/prefix/g,prefix);    	$('#'+divId).html(str);		  //绑定事件		  $('#firstPage_'+prefix).delegate(this,'click', function() {	   firstPage(json,1,pageSize);    });	   $('#prePage_'+prefix).delegate(this,'click', function() {    	prePage(json,currentPage,totalPage,pageSize);    });        $('#nextPage_'+prefix).delegate(this,'click', function() {    	nextPage(json,currentPage,totalPage,pageSize);    });        $('#finalPage_'+prefix).delegate(this,'click', function() {    	finalPage(json,totalPage,pageSize);    });         $('#finalPage_'+prefix).delegate(this,'click', function() {    	finalPage(json,totalPage,pageSize);    });         $('#goToCurrPageBtn_'+prefix).delegate(this,'click', function() {    	goToCurrPageBtn(json,pageSize,totalPage);    });         $('#currPageIpt_'+prefix).delegate(this,'keypress', function(event) {    	if(event.keyCode == "13")            {    		goToCurrPageBtn(json,pageSize,totalPage);        }    }); 	};var prePage = function(json,currentPage, totalPage, pageSize) {	if (currentPage <= 1) {		currentPage = 1;	} else {		currentPage = currentPage - 1;	}	search(json,currentPage, pageSize);};var nextPage = function(json,currentPage, totalPage, pageSize) {	if (currentPage >= totalPage) {		currentPage = totalPage;	} else {		currentPage = currentPage + 1;	}	search(json,currentPage, pageSize);};var firstPage = function(json,currentPage, pageSize) {	search(json,currentPage, pageSize);};var finalPage = function(json,currentPage, pageSize) {	search(json,currentPage, pageSize);};var goToCurrPageBtn = function(json,pageSize, totalPage,keyId) {	var prefix = json["prefix"];	var currPageIptObj = null;	if(keyId==null){		currPageIptObj = $("#currPageIpt_"+prefix);	}else{		currPageIptObj = $("#"+keyId+"_"+prefix);	}	var currPageIpt = currPageIptObj.val();	if (currPageIpt == "") {		currPageIptObj.val("");		win.msg.short("请输入跳转页数!", "W01");	} else if (parseInt(currPageIpt) > totalPage) {		currPageIptObj.val("");		win.msg.short("你输入的页数超出总页数,请输入正确的页数!", "W01");	} else if (parseInt(currPageIpt) <= 0) {		currPageIptObj.val("");		win.msg.short("你输入的页数小于1,请输入正确的页数!", "W01");	} else {		search(json,parseInt(currPageIpt), pageSize);	}};var getPageSrc = function(currentpage,pagesize,totalpage,totalsize){			var pg = {};		pg.currentpage = parseInt(currentpage);		pg.pagesize = parseInt(pagesize);		pg.totalpage = parseInt(totalpage);		pg.totalsize = parseInt(totalsize);		if (pg.totalpage <= 5) {//五页内			var middle = [];			for (var num = 1; num <= pg.totalpage; num++) {				middle.push(num);			}			return renderDom(middle, pg.currentpage, false, false,pg);		} else if (pg.currentpage <= 3) {//当前页为3页内			var middle = [ 1, 2 ];			if (pg.currentpage >= 2) {				middle.push(3);			}			if (pg.currentpage >= 3) {				middle.push(4);			}			return renderDom(middle, pg.currentpage, false, true,pg);		} else if (pg.totalpage - pg.currentpage <= 2) {//当前页为倒数三页内			var middle = [];			if (pg.currentpage <= pg.totalpage - 2) {				middle.push(pg.totalpage - 3);			}			if (pg.currentpage <= pg.totalpage - 1) {				middle.push(pg.totalpage - 2);			}			middle.push(pg.totalpage - 1);			middle.push(pg.totalpage);			return renderDom(middle, pg.currentpage, true, false,pg);		} else {//当前页在中间			return renderDom([ pg.currentpage - 1, pg.currentpage, pg.currentpage + 1 ], pg.currentpage, true, true,pg);		}};var renderDom = function(middle, active, showMore1, showMore2,pg) {	var html = '
1 ? active - 1 : 1)) + '><
'; if (showMore1) { html += '
1
...
'; } $(middle).each(function(key, item) { html += '
' + item + '
'; }); if (showMore2) { html += '
...
' +pg.totalpage + '
'; } html += '
>
'; return html;};

   

跳转至
GO

 

 

 

转载于:https://my.oschina.net/xiaominmin/blog/1597827

你可能感兴趣的文章
linux之权限之隐藏权限
查看>>
系统启动时,spring配置文件解析失败,报”cvc-elt.1: 找不到元素 'beans' 的声明“异常...
查看>>
XDCTF成长记录
查看>>
registered the JDBC driver [com.mysql.jdbc.Driver]
查看>>
Linux系统中的文本处理工具
查看>>
IDE---Python IDE之Eric5在window下的安装
查看>>
python---LineReceiver实现记录服务器
查看>>
Mybatis调用Oracle中的存储过程和function
查看>>
telnet :No route to host
查看>>
基本安装lnmp环境
查看>>
yum源资料汇总
查看>>
7、MTC与MTV,http请求介绍
查看>>
logstash消费阿里云kafka消息
查看>>
第四节课作业
查看>>
angularJS 限制字符串输出长度
查看>>
顺序表的实现---动态
查看>>
SCN转换
查看>>
Tomcat配置
查看>>
我的友情链接
查看>>
云客户端重在连接
查看>>