Home > Web Front-end > JS Tutorial > javascript paging class that supports page number format_javascript skills Jpage Demo - by funnyzak

javascript paging class that supports page number format_javascript skills Jpage Demo - by funnyzak

PHP中文网
Release: 2016-05-16 18:39:46
Original
1677 people have browsed it

Due to project needs, the front-end time needs to display all the attached images under a product in paging. Ajax requests are not considered one by one, so we simply put out all the images at once, and then perform paging when loading. There are many online jquery, property, etc. have all implemented

, but their plug-ins have many ancillary functions that are not needed, and there is no need to reference this library just for such a functional area. Consider it for speed. Of course, it doesn’t matter if your server is good, but In fact, this effect is not necessary, but I think it will be commonly used, so it is packaged into categories for future use and for those who need it to learn and use.

The following is just a simple demo. You can edit the page number style by yourself. There is a default format. No more nonsense, just read it for yourself, there are annotated instructions for use. . . To use the class (3kb), you can refer to the demo. If you don’t understand how to use it, you can leave a message.

In the future, I will slowly write down some common problems encountered in project development, as well as solutions, and share them with everyone.
javascript paging class that supports page number format_javascript skills Jpage Demo - by funnyzak
jpage.js

/* 排序工具 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; 
        } 
    }
Copy after login


The following is the complete test code, js has been included

 
 
 
 
 
Jpage Demo - by funnyzak 
 
 
 
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template