欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼

這篇文章主要為大家展示了用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼,內(nèi)容簡而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來看看吧。

站在用戶的角度思考問題,與客戶深入溝通,找到??稻W(wǎng)站設(shè)計(jì)與保康網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋保康地區(qū)。

思路分析:有3種情況

第一種情況,當(dāng)前頁面curPage < 4

用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼

第二種情況,當(dāng)前頁面curPage == 4

用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼

第三種情況,當(dāng)前頁面curPage>4

用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼

此外,還要考慮,當(dāng)前頁碼 curPage < pageTotal(總頁碼)-2,才顯示 ...

首先,先是前端的布局樣式

<body>
   /*首先,在body中添加div id="pagination" */
   <div id="pagination">
<!-- 后面會(huì)在JS中動(dòng)態(tài)追加 ,此處為了,實(shí)現(xiàn)前端效果,所以注冊(cè)
<a id="prevBtn"><</a>
<a id="first">1</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a>
<span>...</span>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="last">10</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="nextBtn">></a>
-->

   </div>
</body>

其次,是css代碼

*{
      margin: 0;
      padding: 0;
    }
    #pagination{
      width: 500px;
      height: 100px;
      border: 2px solid crimson;
      
      margin: 50px auto ;
      padding-top: 50px ;
      padding-left: 50px;
    }
    
    .over,.pageItem{
      float: left;
      display: block;
      width: 35px;
      height: 35px;
      line-height: 35px;
      text-align: center;
    }
    
    .pageItem{
      border: 1px solid orangered;
      text-decoration: none;
      color: dimgrey;
      margin-right: -1px;/*解決邊框加粗問題*/
    }
    .pageItem:hover{
      background-color: #f98e4594;
      color:orangered ;
    }
    .clearfix{
      clear: both;
    }
    .active{
      background-color: #f98e4594;
      color:orangered ;
    }
    .banBtn{
      border:1px solid #ff980069;
      color: #ff980069;
    }
    #prevBtn{
      margin-right: 10px;
    }
    #nextBtn{
      margin-left: 10px;
    }

JavaScript代碼

<script type="text/javascript">
  
  var pageOptions = {pageTotal:10,curPage:7,paginationId:''};
  dynamicPagingFunc(pageOptions);
  
  function dynamicPagingFunc(pageOptions){
    var pageTotal = pageOptions.pageTotal || 1;
    var curPage = pageOptions.curPage||1;
    var doc = document;
    var paginationId = doc.getElementById(''+pageOptions.paginationId+'') || doc.getElementById('pagination');
    var html = '';
    if(curPage>pageTotal){
      curPage =1;
    }
    /*總頁數(shù)小于5,全部顯示*/
    if(pageTotal<=5){
      html = appendItem(pageTotal,curPage,html);
      paginationId.innerHTML = html;
    }
    /*總頁數(shù)大于5時(shí),要分析當(dāng)前頁*/
    if(pageTotal>5){
      if(curPage<=4){
        html = appendItem(pageTotal,curPage,html);
        paginationId.innerHTML = html;
      }else if(curPage>4){
        html = appendItem(pageTotal,curPage,html);
        paginationId.innerHTML = html;
      }
    }
  }
  
  function appendItem(pageTotal,curPage,html){
    var starPage = 0;
    var endPage = 0;
    
    html+='<a id="prevBtn">&lt;</a>';
    
    if(pageTotal<=5){
      starPage = 1;
      endPage = pageTotal;  
    }else if(pageTotal>5 && curPage<=4){
      starPage = 1;
      endPage = 4;
      if(curPage==4){
        endPage = 5;
      }
    }else{
      if(pageTotal==curPage){
        starPage = curPage-3;
        endPage = curPage;
      }else{
        starPage = curPage-2;
        endPage = curPage+1;
      }
      html += '<a id="first">1</a><span>...</span>';
    }
    
    for(let i = starPage;i <= endPage;i++){
      if(i==curPage){
        html += '<a id="first">'+i+'</a>';
      }else{
        html += '<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'+i+'</a>';
      }
    }
    
    if(pageTotal<=5){
      html+='<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="nextBtn">&gt;</a>';
    }else{
      if(curPage<pageTotal-2){ 
        html += '<span>...</span>';
      }
      if(curPage<=pageTotal-2){
        html += '<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'+pageTotal+'</a>';
      }
      html+='<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="nextBtn">&gt;</a>';
    }
    return html;
  }
  
</script>

以上就是關(guān)于用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。

分享文章:用代碼解析JS如何實(shí)現(xiàn)前端動(dòng)態(tài)分頁碼
地址分享:http://aaarwkj.com/article24/ihpsce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)營銷型網(wǎng)站建設(shè)、網(wǎng)站排名外貿(mào)網(wǎng)站建設(shè)、用戶體驗(yàn)、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
日本高清视频免费一区| 中午字幕久久亚洲精品| 91精品国产色综合久久不| 亚洲区一区二区三区亚洲| 国产传媒在线免费播放| 日本午夜精品在线观看| 2020中文字字幕在线不卡| 日韩一区二区精品网站| 亚洲国产精品久久久精品| 国产精品人妻在线av| 亚洲第一区二区国产精品| 亚洲欧美日韩性生活视频| 久久久人妻91久久久久| 91久久国产香蕉熟女| 国产口爆一区二区三区| 精品日韩av一区二区三区| 2021亚洲精品午夜精品国产| 国产一区二区精品久久岳| 久久国产成人精品免费看| 在线观看视频免费午夜| 日本精品人妻一区二区三区蜜桃| 四虎最新永久在线网站| 午夜香蕉av一区二区三区| 2020亚洲欧美日韩在线| 亚洲国产偷拍在线观看| 久久综合激情亚洲欧美专区| 久久精品高潮999久久久| 中文字幕亚洲精品视频| 91伊人激情综合久久| 日韩三级一区二区三区| 久久久久精品国产亚洲av影院| 亚洲精品成人一区二区| 中文字幕日韩人妻av| 亚洲国产视频不卡一区| 麻豆国产国语精品三级在线观看| 99国产精品欧美一区二区| 国产精品自偷自偷自偷| 亚洲综合美女极品啪啪啪| 国产av一区二区三区中文| 女同三人按摩高潮喷出| 婷婷激情五月国产丝袜|