1 varmodelpage={//Pagination Control2 //Invoke Example3Codeexp:function () {4 Modelpage.initpage ({5pagerowcount:215,//how many data in total?6Pageindex:1,//Current Page7Pagesize:10,//How many pages a page8Domid: ' PageID ',9Pageclick:function(pageindex) {}Ten }) One }, A //pagination mates Meigen Write style use -Initpage:function(setting) { - This. PageContent (setting); the }, -PageContent:function(setting) { - if(!setting.pageindex) Setting.pageindex = 1; - if(!setting.pagesize) Setting.pagesize = 10; + if(!setting.showcount) Setting.showcount = 5; - //alert (setting.pagecount) + if(!setting.pagerowcount) alert ("Missing parameter Pagerowcount"); A if(!setting.domid) alert ("Missing parameter Domid"); at if(!setting.pageclick) alert ("Missing callback function Pageclick"); - if(setting.pagerowcount) { -Setting.pagecount = parseint (setting.pagerowcount% setting.pagesize > 0? (setting.pagerowcount/setting.pagesize) + 1:setting.pagerowcount/setting.pagesize); - } - varItemthis = This; - varDiv_page = document.createelement ("div"); inDiv_page.classname = "Page"; -Div_page.id =Setting.domid; to varDiv_pagein = document.createelement ("div"); +Div_pagein.classname = "Pagein"; - the This. Pageset (setting, Div_pagein, itemthis); * $ Div_page.appendchild (Div_pagein);Panax Notoginseng varDom =document.getElementById (setting.domid); - Dom.parentElement.replaceChild (Div_page, DOM); the }, +Pageset:function(setting, Div_pagein, itemthis) { A /*Handle Paging parameters*/ the if(Setting.pageindex > 1) { + varLink_a = Document.createelement ("a"); -Link_a.innertext = "Home"; $Link_a.onclick =function() {Itemthis.pageclick.call (itemthis, setting, 1); }; $ Div_pagein.appendchild (LINK_A); - varLink_a = Document.createelement ("a"); -Link_a.innertext = "Previous Page"; the if(Setting.pageindex <= 1) link_a.disabled = "Disabled"; - ElseWuyiLink_a.onclick =function() {Itemthis.pageclick.call (itemthis, setting, setting.pageindex-1); }; the Div_pagein.appendchild (LINK_A); - } Wu - //var tempshowcount = Setting.pagecount < Setting.showcount setting.pagecount:setting.showcount; About for(vari = 1; I <= Setting.showcount; i++) { $ varLink_a = Document.createelement ("a"); -Link_a.innertext = parseint ((setting.pageindex-1)/setting.showcount) * Setting.showcount +i; - if(Link_a.innertext > Setting.pagecount) Break; - if(Link_a.innertext = =setting.pageindex) { ALink_a.classname = "Now"; + } the - varPageitem = This; $ theLink_a.onclick =function(pagei) { the return function () { the Itemthis.pageclick.call (itemthis, setting, pagei); the } - } (Link_a.innertext); in Div_pagein.appendchild (LINK_A); the } the About if(Setting.pageindex <setting.pagecount) { the varLink_a = Document.createelement ("a"); theLink_a.innertext = "Next Page"; the if(Setting.pageindex >= setting.pagecount) link_a.disabled = "Disabled"; + ElseLink_a.onclick =function() {Itemthis.pageclick.call (itemthis, setting, Setting.pageindex + 1); }; - Div_pagein.appendchild (LINK_A); the Bayi varLink_a = Document.createelement ("a"); theLink_a.innertext = "Last Page"; theLink_a.onclick =function() {Itemthis.pageclick.call (itemthis, setting, Setting.pagecount);}; - Div_pagein.appendchild (LINK_A); - } the /*working with paging parameters end*/ the }, thePageclick:function(setting, page) { thepage =parseint (page); -Setting.pageindex =page; the This. PageContent (setting); the Setting.pageclick (page); the },94LOADCSS:function () { the varDom = document.createelement ("Style"); theDom.type = "Text/css"; theDom.innertext = ". Page{width:100%;height:auto;margin-top:20px}.page. pagein{width:620px;margin:0 auto}.page. PageIn a{display:inline-block;padding:0 15px;height:40px;border:1px solid #ccc; Margin-right:3px;line-height:40px;color: #555; font-size:14px}.page. PageIn. Now{background: #2dc3e8; border:1px solid #2dc3e8; color: #fff} ";98 Window.document.body.appendChild (DOM); About } - }101 102 Modelpage.initpage ({103pagerowcount:215,//how many data in total?104Pageindex:1,//Current Page thePagesize:10,//How many pages a page106Domid: ' PageID ',107Pageclick:function(pageindex) {}108})
View Code
As follows
"JavaScript" homemade pre-section JS pagination