DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js下通過getList函數實現分頁效果的代碼
js下通過getList函數實現分頁效果的代碼
編輯:關於JavaScript     
用js實現頁面的分頁:

復制代碼 代碼如下:
<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> //按下拉顯示頁數
</form>
</td> </tr>
</table>

getPage()為js函數,如下:

復制代碼 代碼如下:
//參數說明:lblPostsCount:總共記錄條數,由getActivityCount獲得;iPageIndex:全局變量,當前頁數
function getPage(page)
{
if(page==0)//回到首頁
{
iPageIndex=1;
document.form1.PageCtl1_select.options[iPageIndex-1].selected="true"; //下拉框顯示第幾頁,數組從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);//調用List清單
}
}
}

function getActivityCount() //獲取記錄條數
{
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; //記錄總數
  document.form1.PageCtl1_select.length=0; //初始下拉框,把頁數付給下拉框的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);
}
}


按下拉框顯示第幾頁函數:

復制代碼 代碼如下:
function SD_Web_PageCtlGoOtherPage(pageNo)
{
getActivityList(pageNo);
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved