js下通過getList函數(shù)實現(xiàn)分頁效果的代碼
更新時間:2010年09月17日 09:35:01 作者:
js下通過getList函數(shù)實現(xiàn)分頁效果的代碼,需要通過js分頁的朋友可以參考下。
用js實現(xiàn)頁面的分頁:
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color:#D2EBF3;" height="32">
<tr><td align="right" bgColor="#f7f7f7" height="36">
<a href="javascript:void(0)" onclick="getPage(-1)" style="visibility :visible " id="up">上一頁</a>
<a href="javascript:void(0)" onclick="getPage(1)" style="visibility :visible " id="next">下一頁</a>
<a href="javascript:void(0)" onclick="getPage(0)" style="visibility :visible ">首頁</a>
<a href="javascript:void(0)" onclick="getPage(11)">尾 頁</a>
<form name="form1" id="form2">
<select name='PageCtl1_select' id="select" onchange='SD_Web_PageCtlGoOtherPage(this.value);' style="width: 30px"></select> //按下拉顯示頁數(shù)
</form>
</td> </tr>
</table>
getPage()為js函數(shù),如下:
//參數(shù)說明:lblPostsCount:總共記錄條數(shù),由getActivityCount獲得;iPageIndex:全局變量,當前頁數(shù)
function getPage(page)
{
if(page==0)//回到首頁
{
iPageIndex=1;
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true"; //下拉框顯示第幾頁,數(shù)組從0開始
getActivityList(1);
}
else if(page==11)//回到尾頁
{
iPageIndex=Math.round (lblPostsCount/6);
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true";
getActivityList(iPageIndex);
}
else //上一頁,下一頁
{
iPageIndex=iPageIndex+page;
if(iPageIndex<=0) //如果是第一頁還點上一頁,還是保持在第一頁
iPageIndex=1;
else if(iPageIndex>Math.round (lblPostsCount/6))//如果是最后一頁還點下一頁,保持在最后一頁
iPageIndex=Math.round (lblPostsCount/6);
else
{
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true";
getActivityList(iPageIndex);//調(diào)用List清單
}
}
}
function getActivityCount() //獲取記錄條數(shù)
{
var variable=['strWhere'];
var value=new Array(1);
value[0]="iStatus=2 and iPublic=5";
newRequest("getActivityCount",variable,value,getAllActivityCountShow);
beginRequest();
}
function getAllActivityCountShow()
{
var xmlhttp=xmlHttpRequest;
var str=xmlhttp.responseText;
var value=GetValue(str,"getActivityCountResult");
lblPostsCount=value; //記錄總數(shù)
document.form1.PageCtl1_select.length=0; //初始下拉框,把頁數(shù)付給下拉框的value值和text顯示;
for(i=1;i<=Math.round (lblPostsCount/6);i++)
{
var option=document.createElement("option");
option.value=i;
option.text=i;
document.form1.PageCtl1_select.options.add(option);
}
}
按下拉框顯示第幾頁函數(shù):
function SD_Web_PageCtlGoOtherPage(pageNo)
{
getActivityList(pageNo);
}
復制代碼 代碼如下:
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color:#D2EBF3;" height="32">
<tr><td align="right" bgColor="#f7f7f7" height="36">
<a href="javascript:void(0)" onclick="getPage(-1)" style="visibility :visible " id="up">上一頁</a>
<a href="javascript:void(0)" onclick="getPage(1)" style="visibility :visible " id="next">下一頁</a>
<a href="javascript:void(0)" onclick="getPage(0)" style="visibility :visible ">首頁</a>
<a href="javascript:void(0)" onclick="getPage(11)">尾 頁</a>
<form name="form1" id="form2">
<select name='PageCtl1_select' id="select" onchange='SD_Web_PageCtlGoOtherPage(this.value);' style="width: 30px"></select> //按下拉顯示頁數(shù)
</form>
</td> </tr>
</table>
getPage()為js函數(shù),如下:
復制代碼 代碼如下:
//參數(shù)說明:lblPostsCount:總共記錄條數(shù),由getActivityCount獲得;iPageIndex:全局變量,當前頁數(shù)
function getPage(page)
{
if(page==0)//回到首頁
{
iPageIndex=1;
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true"; //下拉框顯示第幾頁,數(shù)組從0開始
getActivityList(1);
}
else if(page==11)//回到尾頁
{
iPageIndex=Math.round (lblPostsCount/6);
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true";
getActivityList(iPageIndex);
}
else //上一頁,下一頁
{
iPageIndex=iPageIndex+page;
if(iPageIndex<=0) //如果是第一頁還點上一頁,還是保持在第一頁
iPageIndex=1;
else if(iPageIndex>Math.round (lblPostsCount/6))//如果是最后一頁還點下一頁,保持在最后一頁
iPageIndex=Math.round (lblPostsCount/6);
else
{
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true";
getActivityList(iPageIndex);//調(diào)用List清單
}
}
}
function getActivityCount() //獲取記錄條數(shù)
{
var variable=['strWhere'];
var value=new Array(1);
value[0]="iStatus=2 and iPublic=5";
newRequest("getActivityCount",variable,value,getAllActivityCountShow);
beginRequest();
}
function getAllActivityCountShow()
{
var xmlhttp=xmlHttpRequest;
var str=xmlhttp.responseText;
var value=GetValue(str,"getActivityCountResult");
lblPostsCount=value; //記錄總數(shù)
document.form1.PageCtl1_select.length=0; //初始下拉框,把頁數(shù)付給下拉框的value值和text顯示;
for(i=1;i<=Math.round (lblPostsCount/6);i++)
{
var option=document.createElement("option");
option.value=i;
option.text=i;
document.form1.PageCtl1_select.options.add(option);
}
}
按下拉框顯示第幾頁函數(shù):
復制代碼 代碼如下:
function SD_Web_PageCtlGoOtherPage(pageNo)
{
getActivityList(pageNo);
}
相關(guān)文章
js監(jiān)控IE火狐瀏覽器關(guān)閉、刷新、回退、前進事件
本節(jié)主要介紹了js監(jiān)控IE火狐瀏覽器關(guān)閉、刷新、回退、前進事件的方法2014-07-07Javascript設(shè)置對象的ReadOnly屬性(示例代碼)
本篇文章主要介紹了Javascript設(shè)置對象的ReadOnly屬性(示例代碼) 需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12JavaScript實現(xiàn)動態(tài)增刪表格的方法
本篇文章主要介紹了JavaScript實現(xiàn)動態(tài)增刪表格,可以實現(xiàn)表格增加和刪除數(shù)據(jù)的功能,非常具有實用價值,有興趣的可以了解一下2017-03-03