前端时间因为项目需要,要对一个产品下所有的附属图片进行分页显示,没考虑ajax一张张请求,所以干脆一次性全部把图片out,然后在载入的时候进行分页,网上很多jquery,property等都实现了,但是他们插件的附属功能很多又不需要,而且没必要就为了这么一个功能区引用这个库,为速度考虑吧,当然你服务器好也行,但是其实这个效果不是必须的,但是觉的会常用,所以就包装成类了,供以后使用,也供有需要的人学习使用。

下面只是一个简单的demo,用的话自己可以在编辑页码样式,有默认的格式。不废话了,自己看吧,有注释使用说明。。。类(3kb)使用可以参照demo,不明白使用的可以留言。

以后会慢慢写一些项目开发中常遇到的问题,以及解决方案,和大家学习分享。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { text-align:center; padding:20px 0 0 0; font-size:12px; } a { color:#000; font-size:12px; cursor:pointer; } ul, li { margin:0; padding:0; list-style:none; } .contain { margin:0 auto; width:825px; text-align:left; border:1px #000 solid; padding:5px; height:auto; } li.sd a,li.sd a:link,li.sd a:visited{background-color:#000; color:#FFF; font-size:13px;} </style> <title>Jpage Demo - by funnyzak</title> <script type="text/javascript"> /* 排序工具 by Funny ZAk <silenceacegmail.com> 2009-8-23 "调用方式 var zp = new zakPage(参数);zp.init(); 参数以此为 源内容容器,分页结果容器,导航容器,页大小,单挑内容回调函数返回li对象,每个li的样式,选择后的样式没有则为null或"" ,默认起始页数,格式化页码显示格式*/ function zakPage(id,pagec,navid,pagesize,lievt,ds,ss,idx,navp){ this.obj = this; this.pageid = id; this.pagec = pagec; this.navc = navid; this.pagesize = pagesize || 7; this.lievt = lievt || null; this.rcount = 0; this.pagecount = 0; this.cpage = 1; this.ds = ds; if(this.ds == null){this.ds = "";} this.ss = ss; if(this.ss == null){this.ss = "";} this.idx = idx; this.navpre = navp || ["共{$pcount}页/{$rcount}条,当前第{cpage}页","首页","上一页","下一页","末页"]; } zakPage.prototype = { init:function(){ document.getElementById(this.pageid).style.display = "none"; this.rcount = document.getElementById(this.pageid).getElementsByTagName("li").length; var residue = this.rcount%this.pagesize; var nums = parseInt(this.rcount/this.pagesize); this.pagecount = nums; if(residue != 0){this.pagecount = nums+1;} this.gopage(this.idx); }, guide:function(){ var nav = document.getElementById(this.navc); var np = this.navpre; nav.innerHTML = np[0].replace("{$rcount}",this.rcount).replace("{$pcount}",this.pagecount).replace("{cpage}",this.cpage); nav.appendChild(this.createa(np[1],1)); nav.appendChild(this.createa(np[2],this.cpage-1)); nav.appendChild(this.createa(np[3],this.cpage+1)); nav.appendChild(this.createa(np[4],this.pagecount)); }, createa:function(html,index){ var aa = document.createElement("a"); aa.innerHTML = html; var o = this.obj; aa.onclick = function(){o.gopage(index);} return aa; }, gopage:function(index){ if(index>this.pagecount){index=1;} if(index<=0){index = this.pagecount;} this.cpage = index; var ghtml = document.getElementById(this.pagec); ghtml.innerHTML = ""; var pages = (index-1)*this.pagesize; var pagee = pages+this.pagesize; if(pagee>this.rcount){pagee = this.rcount;} for(var i=pages;i<pagee;i++){ var lil = document.createElement("li"); lil.className = this.ds; lil.innerHTML = this.litem(i); var sss = this.ss; if(this.lievt !=null){ lil.lievt = this.lievt; lil.onclick = function(){ this.lievt(this); this.className = sss; } } ghtml.appendChild(lil); } this.guide(); }, litem:function(index){ return document.getElementById(this.pageid).getElementsByTagName("li")[index].innerHTML; } } </script> </head> <body> <div class="contain"> <ul id="jpage"> <li><a href="http://mo.zzit.com.cn/labs/20091128/232363.shtml" target="_blank" mon="ct=0&a=27&c=technnews">侧滑全键盘 LG首款谷歌手机GW620评测</a></li> <li><a href="http://mo.zzit.com.cn/market/20091128/232573.shtml" target="_blank" mon="ct=0&a=27&c=technnews">简约大气 三星3G音乐新机M519仅1280</a></li> <li><a href="http://article.pchome.net/content-1014181.html" target="_blank" mon="ct=0&a=27&c=technnews">诺基亚N86 全能表现800万像素仅售2K6</a></li> <li><a href="http://mo.zzit.com.cn/new/20091128/232605.shtml" target="_blank" mon="ct=0&a=27&c=technnews">WM6.5系统 惠普iPaq Glisten手机发布</a></li> <li><a href="http://mo.zzit.com.cn/buy/20091128/232622.shtml" target="_blank" mon="ct=0&a=27&c=technnews">享受完美视觉盛宴 经典高清大屏手机推荐</a></li> <li><a href="http://internal.dbw.cn/system/2009/11/27/052239606.shtml" target="_blank" mon="ct=0&a=27&col=7">湖南一周死亡6名甲流患者</a></li> <li><a href="http://news.sina.com.cn/c/2009-11-28/125416684006s.shtml" target="_blank" mon="ct=0&a=27&col=7">三鹿破产债权清偿率为零 对结石患儿无钱可赔</a></li> <li><a href="http://news.xinmin.cn/rollnews/2009/11/27/2990106.html" target="_blank" mon="ct=0&a=27&col=7">《蜗居》主演海清鸣不平:单纯批评海藻不公平</a></li> <li><a href="http://news.xinmin.cn/rollnews/2009/11/28/2992331.html" target="_blank" mon="ct=0&a=27&col=7">林志玲沙漠体验浪人滋味 称惨遭周杰伦捉弄(图)</a></li> <li><a href="http://news.cctv.com/law/20091128/100454.shtml" target="_blank" mon="ct=0&a=27&col=7">南京致5死4伤醉驾案公审 张明宝流泪大喊对不起</a></li> <li><a href="http://tv.sohu.com/20091128/n268540542.shtml" target="_blank" mon="ct=0&a=27&col=7">视频:沈阳老虎咬人事件原因查明 积雪致电网失效</a></li> <li><a href="http://sports.sohu.com/20091128/n268535705.shtml" target="_blank" mon="ct=0&a=27&col=7">幸运彩民逛街也不忘买彩 喜中"红樱桃"4000元</a></li> <li><a href="http://finance.sina.com.cn/money/forex/20091128/04277029051.shtml" target="_blank">迪拜债务危机推动美元忽然大涨</a><span class="time"> 04:27</span></li> <li><a href="http://finance.sina.com.cn/money/fund/20091128/04057028862.shtml" target="_blank">牛市愿景VS震荡加剧 指基投资陷入囚徒困境 </a><span class="time"> 04:05</span></li> <li><a href="http://finance.sina.com.cn/money/fund/20091128/04057028859.shtml" target="_blank">低风险产品是亮点 11月中下旬新基金发行综述</a><span class="time"> 04:05</span></li> <!-- --> <li><a href="http://finance.sina.com.cn/consume/20091129/11257030393.shtml" target="_blank">国泰航空飞机10个厕所全坏掉 被迫提前着陆</a><span class="time"> 11:25</span></li> <li><a href="http://finance.sina.com.cn/consume/20091128/10237029443.shtml" target="_blank">广州奢侈品展开幕 买家争求8000万元巨钻</a><span class="time"> 10:23</span></li> <li><a href="http://finance.sina.com.cn/stock/cngem/gemipo/20091129/20347030740.shtml" target="_blank">大禹节水30日起复牌 不存在未披露重大事项</a><span class="time"> 20:34</span></li> <li><a href="http://finance.sina.com.cn/stock/cngem/gemipo/20091129/16417030615.shtml" target="_blank">创业板第一高价股神州泰岳11月30日起停牌核实</a><span class="time"> 16:41</span></li> <li><a href="http://finance.sina.com.cn/stock/y/20091129/16177030594.shtml" target="_blank">周末影响市场重要资讯回顾及展望</a><span class="time"> 16:17</span></li> <li><a href="http://finance.sina.com.cn/stock/s/20091129/15467030568.shtml" target="_blank">大杨创世:受到巴菲特青睐的中国裁缝商</a><span class="time"> 15:46</span></li> <li><a href="http://finance.sina.com.cn/stock/s/20091129/10197030320.shtml" target="_blank">莲花味精涨价成游资噱头 机构高位接盘令人难解</a><span class="time"> 10:19</span></li> <li><a href="http://finance.sina.com.cn/stock/data/20091128/16487029826.shtml" target="_blank">下周A股限售股解禁市值环比下降逾四成 </a><span class="time"> 16:48</span></li> <li><a href="http://finance.sina.com.cn/stock/hkstock/hkstocknews/20091127/21417027999.shtml" target="_blank">曾俊华:迪拜债务危机对香港银行业影响不大</a><span class="time"> 21:41</span></li> <li><a href="http://mo.zzit.com.cn/labs/20091128/232363.shtml" target="_blank" mon="ct=0&a=27&c=technnews">侧滑全键盘 LG首款谷歌手机GW620评测</a></li> <li><a href="http://mo.zzit.com.cn/market/20091128/232573.shtml" target="_blank" mon="ct=0&a=27&c=technnews">简约大气 三星3G音乐新机M519仅1280</a></li> <li><a href="http://article.pchome.net/content-1014181.html" target="_blank" mon="ct=0&a=27&c=technnews">诺基亚N86 全能表现800万像素仅售2K6</a></li> <li><a href="http://mo.zzit.com.cn/new/20091128/232605.shtml" target="_blank" mon="ct=0&a=27&c=technnews">WM6.5系统 惠普iPaq Glisten手机发布</a></li> <li><a href="http://mo.zzit.com.cn/buy/20091128/232622.shtml" target="_blank" mon="ct=0&a=27&c=technnews">享受完美视觉盛宴 经典高清大屏手机推荐</a></li> <li><a href="http://internal.dbw.cn/system/2009/11/27/052239606.shtml" target="_blank" mon="ct=0&a=27&col=7">湖南一周死亡6名甲流患者</a></li> <li><a href="http://news.sina.com.cn/c/2009-11-28/125416684006s.shtml" target="_blank" mon="ct=0&a=27&col=7">三鹿破产债权清偿率为零 对结石患儿无钱可赔</a></li> <li><a href="http://news.xinmin.cn/rollnews/2009/11/27/2990106.html" target="_blank" mon="ct=0&a=27&col=7">《蜗居》主演海清鸣不平:单纯批评海藻不公平</a></li> <li><a href="http://news.xinmin.cn/rollnews/2009/11/28/2992331.html" target="_blank" mon="ct=0&a=27&col=7">林志玲沙漠体验浪人滋味 称惨遭周杰伦捉弄(图)</a></li> <li><a href="http://news.cctv.com/law/20091128/100454.shtml" target="_blank" mon="ct=0&a=27&col=7">南京致5死4伤醉驾案公审 张明宝流泪大喊对不起</a></li> <li><a href="http://tv.sohu.com/20091128/n268540542.shtml" target="_blank" mon="ct=0&a=27&col=7">视频:沈阳老虎咬人事件原因查明 积雪致电网失效</a></li> <li><a href="http://sports.sohu.com/20091128/n268535705.shtml" target="_blank" mon="ct=0&a=27&col=7">幸运彩民逛街也不忘买彩 喜中"红樱桃"4000元</a></li> <li><a href="http://finance.sina.com.cn/money/forex/20091128/04277029051.shtml" target="_blank">迪拜债务危机推动美元忽然大涨</a><span class="time"> 04:27</span></li> <li><a href="http://finance.sina.com.cn/money/fund/20091128/04057028862.shtml" target="_blank">牛市愿景VS震荡加剧 指基投资陷入囚徒困境 </a><span class="time"> 04:05</span></li> <li><a href="http://finance.sina.com.cn/money/fund/20091128/04057028859.shtml" target="_blank">低风险产品是亮点 11月中下旬新基金发行综述</a><span class="time"> 04:05</span></li> <!-- --> <li><a href="http://finance.sina.com.cn/consume/20091129/11257030393.shtml" target="_blank">国泰航空飞机10个厕所全坏掉 被迫提前着陆</a><span class="time"> 11:25</span></li> <li><a href="http://finance.sina.com.cn/consume/20091128/10237029443.shtml" target="_blank">广州奢侈品展开幕 买家争求8000万元巨钻</a><span class="time"> 10:23</span></li> <li><a href="http://finance.sina.com.cn/stock/cngem/gemipo/20091129/20347030740.shtml" target="_blank">大禹节水30日起复牌 不存在未披露重大事项</a><span class="time"> 20:34</span></li> <li><a href="http://finance.sina.com.cn/stock/cngem/gemipo/20091129/16417030615.shtml" target="_blank">创业板第一高价股神州泰岳11月30日起停牌核实</a><span class="time"> 16:41</span></li> <li><a href="http://finance.sina.com.cn/stock/y/20091129/16177030594.shtml" target="_blank">周末影响市场重要资讯回顾及展望</a><span class="time"> 16:17</span></li> <li><a href="http://finance.sina.com.cn/stock/s/20091129/15467030568.shtml" target="_blank">大杨创世:受到巴菲特青睐的中国裁缝商</a><span class="time"> 15:46</span></li> <li><a href="http://finance.sina.com.cn/stock/s/20091129/10197030320.shtml" target="_blank">莲花味精涨价成游资噱头 机构高位接盘令人难解</a><span class="time"> 10:19</span></li> <li><a href="http://finance.sina.com.cn/stock/data/20091128/16487029826.shtml" target="_blank">下周A股限售股解禁市值环比下降逾四成 </a><span class="time"> 16:48</span></li> <li><a href="http://finance.sina.com.cn/stock/hkstock/hkstocknews/20091127/21417027999.shtml" target="_blank">曾俊华:迪拜债务危机对香港银行业影响不大</a><span class="time"> 21:41</span></li> </ul> <ul id="pagec"> </ul> </div> <div id="navs"></div> <script type="text/javascript"> function bb(a){alert(a.innerHTML);} var arr = ["{$rcount}record,total{$pcount}page currenpage{cpage} "," indexpage"," prevpage "," nextpage "," lastpage "]; var zp = new zakPage("jpage","pagec","navs",15,bb,null,null,4,null); //此为默认页码格式 //var zp = new zakPage("jpage","pagec","navs",15,bb,null,null,4,arr); //自定义页码格式 zp.init(); </script> </body> </html>

运行代码

转载于:https://www.cnblogs.com/leonn/archive/2009/12/08/1619194.html

javascript分页类支持页码格式相关推荐

  1. php分页怎么实行跳转,php分页函数,支持页码下拉选择跳转

    //分页 if(!function_exists("pageDivide")){ #$total信息总数 #$shownu显示数量,默认20 #$url本页链接 function ...

  2. php地址后面拼接页码,php分页类尾部页码导航代码

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 $str=$str.$this->commonTag($i); } $str=$str.$this->currentTag(); $str=$ ...

  3. php分页代码简单实现原理,php分页类之PHP分页原理+代码实现

    首先了解SQL语句中的limit用法 SELECT * FROM table -- limit 开始位置 , 操作条数 (其中开始位置是从0开始的) 例子: 取前20条记录:SELECT * FROM ...

  4. phppage类封装分页功能_php显示页码分页类的封装

    本文实例为大家分享了php封装显示页码的分页类,供大家参考,具体内容如下 一.代码 conn.php class Mysql{ public function __construct(){ $this ...

  5. javascript 原生类 DOMParser 把 字符串格式的HTML文档源码 转换成 document DOM对象

    文章目录 Intro QA DOMParser 在 console 的使用 cheerio 在 node 项目中的使用 Reference 测试 sum Intro 有一天我在写爬虫. 其实也说不上是 ...

  6. php显示固定页码,php显示页码分页类的封装

    搜索热词 本文实例为大家分享了PHP封装显示页码的分页类,供大家参考,具体内容如下 一.代码 conn.PHP PHP;"> connect(); } public function ...

  7. 邮件发送类,支持HTML格式,支持优先级设置

    www.chinacs.net  2002-5-9  中文C#技术站 邮件发送类,支持HTML格式,支持优先级设置.通过SOCKET类实现的 using System; using System.Te ...

  8. asp分页类--添加支持重写功能

    Code <% '=============================================== ' 分页类 ' Author : s1ihome (cnsdsxg@gmail. ...

  9. PHP分页类(较完美)

    <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

最新文章

  1. SZUACM集训字符串基础总结: 字符串最小表示 ,KMP, EXKMP, Manracher, Trie树,字符串的hash; 附带一写常见的运用技巧,邝斌大佬的板子和例题[持续更新]
  2. 移除HTML5 input在type=number时的上下小箭头
  3. Qt小游戏《2048》源码(含大量注释)
  4. Java调试器和超时
  5. MySQL在Django框架下的基本操作(MySQL在Linux下配置)
  6. java中session对象登录_JavaWeb中Session对象的学习笔记
  7. 前端学习(1890)vue之电商管理系统电商系统之绘获取用户列表数据
  8. 奥特曼系列ol服务器名称带怪兽,《奥特曼系列ol》怪兽图鉴 怪兽阵容
  9. php 创mysql_PHP MySQL 创建表
  10. python 第3天
  11. cuda并行编程之求解ConjugateGradient(共轭梯度迭代)丢失dll解决方式
  12. JavaSE--类与对象
  13. NI VISION视觉安装
  14. 用125行C语言编写一个简单的16位虚拟机
  15. WordPress 速度优化的完整指南
  16. 大疆2018网申之机器学习算法工程师笔试题B卷
  17. Spring(三) 表单页面处理
  18. 【小程序开发】开发一个短信登录验证(后端采用springboot)
  19. 计算机图形学椭圆Java代码,【计算机图形学】二、椭圆的生成
  20. vue3 Component inside <Transition> renders non-element root node that cannot be animated.

热门文章

  1. 杰里之静电处理方法【篇3】
  2. 【计算机毕业设计】视频点播系统
  3. 2021年成人大专多长时间拿证?要几年?
  4. 边框0.5px实现方法
  5. 架构师花费近一年时间整理出来的Java核心知识,100%好评!
  6. 员工签到系统mysql_jsp+mysql 员工签到系统
  7. Math.round()什么作用?
  8. 数据压缩作业 1.1清音、浊音、爆破音的时域和频域特性分析
  9. win2019操作系统服务器很卡,windows server 2019 远程桌面登陆后出现卡死
  10. wpf 点击按钮弹出新对话框_wpf弹出输入对话框