jquery 分页控件实现代码

2016-02-19 14:44 4 1 收藏

想要天天向上,就要懂得享受学习。图老师为大家推荐jquery 分页控件实现代码,精彩的内容需要你们用心的阅读。还在等什么快点来看看吧!

【 tulaoshi.com - Web开发 】

代码如下:
!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
titlejquery分页控件/title
script src="jquery-1.3.min.js" type="text/javascript"/script
/head
body
div class="pager"/div
!--div
select class="SEID"
option10/option
option selected="selected" 20/option
option30/option
/select
div class="first"首页/div
div class="pre"上一页/div
div class="centerclass"/div
div class="next"下一页/div
div class="last"最后一页/div
input type="text" value="1" / ofspan class="totelspan"0/span
/div--
/body
/html
script type="text/javascript"
var pageindex=1;
var totelsize=60;
var centersize=5;
var pagesize=0;
var totelSec=0;
var outStr="";
var se="select class="SEID""
+"option5/option"
+"option selected="selected" 10/option"
+"option15/option"
+"/select";
var firstdiv="div class="first"首页/div";
var prediv="div class="pre"上一页/div";
var centerdiv="div class="centerclass"/div";
var nextdiv="div class="next"下一页/div";
var lastdiv="div class="last"最后一页/div";
$('.pager').empty();
$('.pager').append(se)
$('.pager').append(firstdiv)
$('.pager').append(prediv)
$('.pager').append(centerdiv)
$('.pager').append(nextdiv)
$('.pager').append(lastdiv)
function PageInit()
{
var size=0;
var barObj=this;
var PageReinit=function()
{
pagesize=$(".SEID option:selected")[0].innerText;
size=parseInt(totelsize/pagesize)
var lastSize=totelsize%pagesize;//最后一页显示记录
if(lastSize0)
{
size=size+1;
}
totelSec=parseInt(size/centersize);
var leftSize=size%centersize;//最后一个区段的显示记录
if(leftSize0)
{
totelSec =totelSec+1;
}
PageBarinit();
}
var reSetPage=function()
{
pageindex=1;
pagesize=0;
totelSec=0;
outStr="";
}
// alert('总页数:'+size)
// alert('总区段:'+totelSec)
// alert('每页记录数:'+pagesize);
var SeClick=function(e)
{
var Selectindex=e.target[e.target.selectedIndex].innerText;
pagesize=parseInt(Selectindex);
alert('每页显示:'+Selectindex);
reSetPage();
PageReinit();
}
var firstClick=function(e)
{
alert('点击到首页');
if(pageindex!=1)
{
pageindex=1;
alert('到了第1页');
}
}
var preClick=function(e)
{
alert('点击到上一页');
if(pageindex!=1)
{
pageindex =pageindex-1;
alert('到了第'+pageindex+'页');
}
ChangeCenterBar(pageindex+1);
}
var pageClick=function(e)
{
var targePage=parseInt(e.target.innerText);
pageindex=targePage;
alert('点击了第'+targePage+"页");
ChangeCenterBar(targePage);
}
var nextClick=function(e)
{
alert('点击了下一页');
if(pageindexsize)
{
pageindex =pageindex+1;
if(pageindex==size)
{
alert('到了最后一页');
}
else{
alert('到了第'+pageindex+'页');
}
}
ChangeCenterBar(pageindex-1);
}
var lastClick=function(e)
{
alert('点击了最后一页');
if(pageindexsize)
{
pageindex=size;
alert('到了第'+size+'页');
}
}
var ChangeCenterBar=function(CurrentIndex)
{
var currentSec=parseInt(CurrentIndex/centersize);
if( CurrentIndex%centersize==1)
{
if(currentSectotelSec)
{ PageBarinit();}
}
if(CurrentIndex%centersize==0)
{
var currentSec=parseInt(CurrentIndex/centersize);
if(currentSectotelSec)
{ PageBarinit();}
}
}
var PageBarinit=function()
{
$('.SEID').unbind('change',SeClick);
$('.first').unbind('click',firstClick);
$('.pre').unbind('click',preClick);
$('.next').unbind('click',nextClick);
$('.last').unbind('click',lastClick);
$('.SEID').bind('change',SeClick);
$('.first').bind('click',firstClick);
$('.pre').bind('click',preClick);
$('.next').bind('click',nextClick);
$('.last').bind('click',lastClick);
if(size=centersize)
{
$('.centerclass').empty();
for(var i=1;i=size;i++)
{
var cdiv="span id='Page_"+String(i)+"'"+i+"/span";
$('.centerclass').append(cdiv);
$("#Page_"+i).bind('click',pageClick);
}
}else if(sizecentersize)
{
$('.centerclass').empty();
if( pageindex%centersize==0)
{
var currentSec=parseInt(pageindex/centersize);//当前区段
if(currentSectotelSec)
{
// alert(9)
var startIndex=(currentSec-1)*centersize+1;
for(startIndex;startIndex=currentSec*centersize;startIndex++)
{
//alert(startIndex)
//alert('最大'+currentSec*centersize);
var cdiv="span id='Page_"+String(startIndex)+"'"+startIndex+"/span";
$('.centerclass').append(cdiv);
$("#Page_"+startIndex).bind('click',pageClick);
}
}
else if(currentSec==totelSec)
{
var startIndex=(currentSec-1)*centersize+1;
for(startIndex;startIndex=currentSec*centersize;startIndex++)
{
var cdiv="span id='Page_"+String(startIndex)+"'"+startIndex+"/span";
$('.centerclass').append(cdiv);
$("#Page_"+startIndex).bind('click',pageClick);
}
}else{
alert('分页出错');
}
}else if(pageindex%centersize0)
{
var currentSec=parseInt(pageindex/centersize)+1;//当前区段
if(currentSectotelSec)
{
var startIndex=(currentSec-1)*centersize+1;
for(startIndex;startIndex=((currentSec-1)*centersize+centersize);startIndex++)
{
var cdiv="span id='Page_"+String(startIndex)+"'"+startIndex+"/span";
$('.centerclass').append(cdiv);
$("#Page_"+startIndex).bind('click',pageClick);
}
}
else if(currentSec==totelSec){
var startIndex=(currentSec-1)*centersize+1;
for(startIndex;startIndex=((currentSec-1)*centersize +size%centersize);startIndex++)
{
var cdiv="span id='Page_"+String(startIndex)+"'"+startIndex+"/span";
$('.centerclass').append(cdiv);
$("#Page_"+startIndex).bind('click',pageClick);
}
}else
{
alert('分页出错');
}
}
}
}
PageReinit();
}
PageInit();
/script

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

来源:https://www.tulaoshi.com/n/20160219/1607737.html

延伸阅读
标签: Web开发
其中有mask()和unmask()这两个方法,这两个方法在指定的元素上添加一个遮罩层和一个提示消息实现,增加客户体验。由于最近做项目的时候,发现有时为了使用这一两个方法需要引入一个比较“庞大”的Extjs进来,觉得有点不划算,于是自己用jquery实现了一个比较简单mask、unmask方法来实现该效果。大家知道jquery是一个优秀的javascript框架,不但...
标签: Web开发
打包下载 查了一下jq的官方插件编写文档( http://docs.jquery.com/Plugins/Authoring )以及文档中推荐的Mike Alsup写的一篇 A Plugin Development Pattern 。英语不是很好,但还是努力看下来(既学习到知识又能练习英语,何乐不为),照猫画虎的写了一个处女作——tabBox。 顾名思义,这个插件就是方便的产生具有tab选项卡功能“盒子...
标签: Web开发
基于jquery的锁定弹出层 这个东西也是随手总结出来的,引用了一些js框架jquery的方法。 div遮盖其他控件的方法参考了 对于需要遮盖flash的,请将flash控件的WMode变量值设置为Transparent 使用方法: 代码如下: script src="jquery.js"/script script src="effect/maskDiv.js"/script script //配置模块 var moduleEvent = [{"i...
标签: Web开发
应用背景 当用户需要某项功能时要填写一些表单信息,在填写完成并提交后,该部分信息是不允许再次修改的。表单包含TextBox、DropDownList、CheckBox等控件。 需求实现 第一种方案,绑定用户填写的数据时,设置控件的Enable属性为False。如果页面的表单数较少时可采用这样的方法,但是如果在表单较多的情况下则并不是更好的方法。 第...
标签: Web开发
多选效果如下图 代码如下: 代码如下: script type="text/javascript"!-- $(document).ready(function() { $("#selectall").click(selectAll); }); function selectAll() { var checked = $("#selectall").attr("checked"); $(".selectable").each(function() { var subchecked = $(this).attr("checked"); if (subchecked != ch...

经验教程

707

收藏

48
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部