国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery 分頁控件實現代碼

2019-11-21 00:57:12
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

<!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>
<title>jquery分頁控件</title>
<script src="jquery-1.3.min.js" type="text/javascript"></script>
</head>
<body>
<div class="pager"></div>
<!--<div>
<select class="SEID">
<option>10</option>
<option selected="selected" >20</option>
<option>30</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" /> of<span 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/">"
+"<option>5</option>"
+"<option selected=/"selected/" >10</option>"
+"<option>15</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(lastSize>0)
{
size=size+1;
}
totelSec=parseInt(size/centersize);
var leftSize=size%centersize;//最后一個區段的顯示記錄
if(leftSize>0)
{
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(pageindex<size)
{
pageindex =pageindex+1;
if(pageindex==size)
{
alert('到了最后一頁');
}
else{
alert('到了第'+pageindex+'頁');
}
}
ChangeCenterBar(pageindex-1);
}
var lastClick=function(e)
{
alert('點擊了最后一頁');
if(pageindex<size)
{
pageindex=size;
alert('到了第'+size+'頁');
}
}
var ChangeCenterBar=function(CurrentIndex)
{
var currentSec=parseInt(CurrentIndex/centersize);
if( CurrentIndex%centersize==1)
{
if(currentSec<totelSec)
{ PageBarinit();}
}
if(CurrentIndex%centersize==0)
{
var currentSec=parseInt(CurrentIndex/centersize);
if(currentSec<totelSec)
{ 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(size>centersize)
{
$('.centerclass').empty();
if( pageindex%centersize==0)
{
var currentSec=parseInt(pageindex/centersize);//當前區段
if(currentSec<totelSec)
{
// 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%centersize>0)
{
var currentSec=parseInt(pageindex/centersize)+1;//當前區段
if(currentSec<totelSec)
{
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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 右玉县| 东乌珠穆沁旗| 巨鹿县| 富裕县| 镇原县| 巫山县| 安图县| 睢宁县| 保山市| 江永县| 探索| 鹰潭市| 弥勒县| 加查县| 阜宁县| 项城市| 高密市| 讷河市| 崇文区| 锦州市| 苏尼特右旗| 合阳县| 安仁县| 长治市| 阿勒泰市| 凤翔县| 湖口县| 曲松县| 肥乡县| 汝南县| 乌鲁木齐县| 阳山县| 呈贡县| 怀仁县| 中方县| 砚山县| 武宁县| 攀枝花市| 乐昌市| 鲁甸县| 五峰|