纯JavaScript分页插件详解编程语言
2023-06-13 09:20:25 时间
var pageNum=Number(10);
/* //最大显示的页码的数目(可选,默认显示5个页码,页码数目必须大于等于1) */
var maxPageNum=Number(5);
//以下可忽略
var count = (Num%pageNum) 0?(Num/pageNum+1):(Num/pageNum); count=Math.floor(count);//取整转化为数据类型 //显示的最小页码, var first=1; //显示的最大页码,首先last =count;其次last是小于等于count的最大数//last=index+maxPageNum/2; var last =1; var decrease=Math.floor(maxPageNum/2);//当前页向上增加值 var increase=Math.floor(maxPageNum/2);//当前页向下减少值 if(maxPageNum =1){ if(maxPageNum==1){//最多显示一页时 first=index =count?index:count; last=index =count?index:count; }else{ //first要大于零 first=(index-decrease); while(first =0){ first++; //first判断显示的最后一页 if((count-index) =decrease){ var diff=count-first; while(diff maxPageNum-1){ if(first==1){ break; }else{ --first; diff=count-first; //last要小于count last=(index+increase); while(last =1){ if(last =count){ break; last--; //last//判断显示的最后一页与maxPageNum的关系 last=last =maxPageNum?last:(maxPageNum count?count:maxPageNum); }else{ alert("至少需要显示一个页码!"); var prev = index - 1;//上一页 var next = index+ 1;//下一页 var str = " tr if(count==0){ str += " td 共 a href=# 0 /a 页 /td td }else if(index count||index =0){ str=" td 页码超出范围 /td }else if (count 0) { str += " td if(first 1){ str += " nbsp; nbsp; span ... nbsp; nbsp;"; var i=1; for(i=first;i =last; i++){ if(i==index){ str += " nbsp; nbsp; a href=# [" + i+ "] /a nbsp; nbsp;"; }else{ str += " nbsp; nbsp; a href=# " + i+ " /a nbsp; nbsp;"; if(last count){ str += " nbsp; nbsp; span ... nbsp; nbsp;"; str+=" /td td 共 a href=#first "+ Num +" /a 条 /td /* if(index!=1){ str +=" td a href=# id=prev 上一页 /a /td if(index count){ str +=" td a href=# id=next 下一页 /a /td }*/ if(index!=1 count 1){ str += " td nbsp; nbsp; a href=# id=first name=first 首页 /a nbsp; nbsp; /td if(index!=count count 1 index count){ str += " td nbsp; nbsp; a href=# 尾页 /a nbsp; nbsp; /td str+=" /tr
function submit(pageIndex) { //var sortInfo = $.getUrlParam(sortInfo);//判断是哪一个页面的查询 var url = " ?php echo current_url();? ?page="+pageIndex+" field= ?php echo$field;? value= ?php echo $field_value;? window.location.href=url;
var count = (Num%pageNum) 0?(Num/pageNum+1):(Num/pageNum); count=Math.floor(count);//取整转化为数据类型 //显示的最小页码, var first=1; //显示的最大页码,首先last =count;其次last是小于等于count的最大数//last=index+maxPageNum/2; var last =1; var decrease=Math.floor(maxPageNum/2);//当前页向上增加值 var increase=Math.floor(maxPageNum/2);//当前页向下减少值 if(maxPageNum =1){ if(maxPageNum==1){//最多显示一页时 first=index =count?index:count; last=index =count?index:count; }else{ //first要大于零 first=(index-decrease); while(first =0){ first++; //first判断显示的最后一页 if((count-index) =decrease){ var diff=count-first; while(diff maxPageNum-1){ if(first==1){ break; }else{ --first; diff=count-first; //last要小于count last=(index+increase); while(last =1){ if(last =count){ break; last--; //last//判断显示的最后一页与maxPageNum的关系 last=last =maxPageNum?last:(maxPageNum count?count:maxPageNum); }else{ alert("至少需要显示一个页码!"); var prev = index - 1;//上一页 var next = index+ 1;//下一页 var str = " tr if(count==0){ str += " td 共 a href=# 0 /a 页 /td td }else if(index count||index =0){ str=" td 页码超出范围 /td }else if (count 0) { str += " td if(first 1){ str += " nbsp; nbsp; span ... nbsp; nbsp;"; var i=1; for(i=first;i =last; i++){ if(i==index){ str += " nbsp; nbsp; a href=# [" + i+ "] /a nbsp; nbsp;"; }else{ str += " nbsp; nbsp; a href=# " + i+ " /a nbsp; nbsp;"; if(last count){ str += " nbsp; nbsp; span ... nbsp; nbsp;"; str+=" /td td 共 a href=#first "+ Num +" /a 条 /td /* if(index!=1){ str +=" td a href=# id=prev 上一页 /a /td if(index count){ str +=" td a href=# id=next 下一页 /a /td }*/ if(index!=1 count 1){ str += " td nbsp; nbsp; a href=# id=first name=first 首页 /a nbsp; nbsp; /td if(index!=count count 1 index count){ str += " td nbsp; nbsp; a href=# 尾页 /a nbsp; nbsp; /td str+=" /tr
function submit(pageIndex) { //var sortInfo = $.getUrlParam(sortInfo);//判断是哪一个页面的查询 var url = " ?php echo current_url();? ?page="+pageIndex+" field= ?php echo$field;? value= ?php echo $field_value;? window.location.href=url;
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8869.html
cjavaphp相关文章
- MySQL数据库使用JavaScript操作基于JavaScript实现MySQL数据库自动化操作(mysql-js)
- 用 JavaScript 运行上世纪 90 年代的 Mac OS 8
- Javascript常用运算符(Operators)-javascript基础教程
- Javascript浅拷贝、深拷贝的实现代码
- javascript密码强弱度检测万能插件
- 一个用javascript写的select支持上下键、首字母筛选以及回车取值的功能
- 用Javascript检查AdobePDF插件是否安装的实现代码
- javascript上下左右定时滚动插件
- 自己整理的一个javascript日期处理函数
- 5个javascript的数字格式化函数分享
- javascript中的onkeyup和onkeydown区别介绍
- 原生javascript和jquery判断浏览器版本等信息
- JAVASCRIPT函数作用域和提前声明分享
- javascript使用location.search的示例
- javascript用函数语句和表达式定义函数的区别详解
- 2014最热门的JavaScript代码高亮插件推荐
- 小米公司JavaScript面试题
- JavaScript插件化开发教程(三)
- JavaScript验证电子邮箱的函数
- 原生javascript实现的分页插件pagenav