js下通過getList函數實現分頁效果的代碼_javascript技巧

來源:互聯網
上載者:User
用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);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.