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

首頁 > 編程 > JavaScript > 正文

純JavaScript實現(xiàn)的分頁插件實例

2019-11-20 12:03:09
字體:
供稿:網(wǎng)友

本文實例講述了純JavaScript實現(xiàn)的分頁插件。分享給大家供大家參考。具體如下:

//總條數(shù)(必填)var Num=Number(<?php echo $count;?>)//當(dāng)前頁(必填)var index = Number(<?php echo $page;?>);/* //每頁的條數(shù)(可選,默認每頁10條) */var pageNum=Number(10); /* //最大顯示的頁碼的數(shù)目(可選,默認顯示5個頁碼,頁碼數(shù)目必須大于等于1) */var maxPageNum=Number(5);//以下可忽略//計算得出總頁數(shù)var count = (Num%pageNum)>0?(Num/pageNum+1):(Num/pageNum);count=Math.floor(count);//取整轉(zhuǎn)化為數(shù)據(jù)類型//顯示的最小頁碼,var first=1;//顯示的最大頁碼,首先last<=count;其次last是小于等于count的最大數(shù)//last=index+maxPageNum/2;var last =1;var decrease=Math.floor(maxPageNum/2);//當(dāng)前頁向上增加值var increase=Math.floor(maxPageNum/2);//當(dāng)前頁向下減少值if(maxPageNum>=1){ if(maxPageNum==1){//最多顯示一頁時  first=index<=count?index:count;   last=index<=count?index:count;   }else{   //first要大于零   first=(index-decrease);   while(first<=0){    first++;   }    //first判斷顯示的最后一頁   if((count-index)<=decrease){    var diff=count-first;    while(diff<maxPageNum-1){     if(first==1){      break;     }else{      --first;      diff=count-first;     }    }   }   //last要小于count   last=(index+increase);   while(last>=1){    if(last<=count){     break;    }    last--;   }    //last//判斷顯示的最后一頁與maxPageNum的關(guān)系   last=last>=maxPageNum?last:(maxPageNum>count?count:maxPageNum); }}else{ alert("至少需要顯示一個頁碼!");}var prev = index - 1;//上一頁var next = index+ 1;//下一頁 var str = "<tr>";if(count==0){ str += "<td>共<a href='#'>0</a>頁</td><td>";}else if(index>count||index<=0){ str="<td style='color:blue;' >頁碼超出范圍</td>";}else if (count > 0) { str += "<td>"; if(first>1){  str += "  <span style='color:#4169E1;' >...</span>  "; } var i=1; for(i=first;i<=last; i++){  if(i==index){   str += "  <a href='#' style='color:#4169E1;' onclick='submit(" + i + ");'>[" + i+ "]</a>  ";  }else{   str += "  <a href='#' onclick='submit(" + i + ");'>" + i+ "</a>  ";  } }   if(last<count){   str += "  <span style='font-size:16px;color:#4169E1;' >...</span>  ";   }  str+="</td><td style='font-size: 14px;'>共<a href='#first' style='color:#4169E1;font-size: 16px;' >"+ Num +"</a>條</td>";  /* if(index!=1){   str +="<td style='width:60px;font-family: 微軟雅黑;font-size: 14px;' ><a href='#' id='prev' onclick='submit(" + prev+ ");'>上一頁</a></td>";   }  if(index<count){   str +="<td style='width:60px;font-family: 微軟雅黑;font-size: 14px;'><a href='#' id='next' onclick='submit("+ next + ");'>下一頁</a></td>";  }*/  if(index!=1&&count>1){   str += "<td style='width:40px;font-family: 微軟雅黑;font-size: 14px;white-space: nowrap;'>  <a href='#' id='first' name='first' onclick='submit(1);'>首頁</a>  </td>";  }  if(index!=count&&count>1&&index<count){   str += "<td style='width:40px;font-family: 微軟雅黑;font-size: 14px;white-space: nowrap;'>  <a href='#' onclick='submit(" + count+ ");'>尾頁</a>  </td>" ;  }    str+="</tr>";}//分頁區(qū)域填寫$('.page').html(str);<table class="page"><tr><td>此處分頁只需要傳遞給我當(dāng)前頁碼和總頁數(shù)即可</td></tr></table>//根據(jù)頁碼查詢,function submit(pageIndex) { //var sortInfo = $.getUrlParam('sortInfo');//判斷是哪一個頁面的查詢 var url = "<?php echo current_url();?>?page="+pageIndex+"&field=<?php echo$field;?>&value=<?php echo $field_value;?>"; window.location.href=url;}

希望本文所述對大家的javascript程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 额尔古纳市| 司法| 富锦市| 安福县| 岐山县| 乐山市| 工布江达县| 张家界市| 双柏县| 武义县| 广东省| 裕民县| 和林格尔县| 平遥县| 中阳县| 嫩江县| 天峻县| 尼勒克县| 贵德县| 紫阳县| 原阳县| 商都县| 从江县| 舟山市| 峨眉山市| 石棉县| 双鸭山市| 苍溪县| 榆中县| 施甸县| 息烽县| 南澳县| 洛宁县| 扬中市| 福鼎市| 固原市| 海丰县| 定西市| 文成县| 郁南县| 渑池县|