亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

javascript實現前端分頁效果

瀏覽:3日期:2023-06-19 16:05:41

本文實例為大家分享了javascript實現前端分頁效果的具體代碼,供大家參考,具體內容如下

需求:實現分頁請求表格數據,ajax暫時沒寫,只寫了分頁的功能。

效果圖:

當頁數是第一頁的時候,首頁和向前那個按鈕處于禁止點擊的狀態

javascript實現前端分頁效果

各個按鈕都正常的狀態

javascript實現前端分頁效果

當頁數是第一頁的時候,首頁和向前那個按鈕處于禁止點擊的狀態

javascript實現前端分頁效果

各部分的代碼如下:

html部分:

<!-- 分頁 --> <div class='pageBox'> <div class='pageTotal'>共<span id='dataLength'>88</span>條</div> <div class='pageContent'> <button class=’firstPage’>首頁</button> <button class='prevPage'></button> <button class='showPage'></button> <button class='nextPage'></button> <button class='lastPage'>尾頁</button> </div> <div class='selectSize'> <div><span class='numSelect'>10</span> <span>條/頁</span></div> <div class='icona'></div> </div> <!-- <div style='display: inline-block;margin-left: 210px;'></div> --> <div class='goPage'><span>跳至</span><input type='text' id='goPageInp'><span>頁</span></div> <ul class='pageSelectShow'> <li data-num='10'>10條/頁</li> <li data-num='20'>20條/頁</li> <li data-num='50'>50條/頁</li> <li data-num='100'>100條/頁</li> </ul> </div>

CSS部分:

* { padding: 0; margin: 0; } body, html { width: 100%; height: 100%; } .pageBox{ width: 60%; margin-left: 20%; margin-top: 200px; position: relative; height: 50px; } .pageBox>div{ float: left; margin: 0 10px; } .pageContent>button{ float: left; margin: 0px 4px; border: none; outline: none; }.goPage,.pageTotal{ height: 30px; vertical-align: middle; font-size: 14px;}.goPage{ right: 50px;}.goPage span{ display: inline-block; color: #999999; }.goPage input{ display: inline-block; width: 50px; height: 30px; margin: 0px 5px; border: none; border: 1px solid #ccc; border-radius: 4px; text-align: center;}.pageTotal{ left: 50px; line-height: 30px; font-size: 15px; color: #999;}.pageTotal span{ margin: 0 3px; color: #333;}.selectSize{ width: 100px; height: 30px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; text-align: center; line-height: 30px; vertical-align: middle; position: relative;}.selectSize>div{ float: left; margin-left: 5px;}.icona{ width: 20px; height: 20px; background-image: url(’./down.png’); background-size: 100% 100%; background-position: center center; margin-top: 5px; cursor: pointer; position: absolute; right: 6px;}.pageSelectShow{ width: 100px; height: 162px; border: 1px solid #ccc; overflow-y: auto; position: absolute; top: -170px; left: 400px; list-style: none; font-size: 15px; display: none; background: #fff; border-radius: 3px;}.pageSelectShow li{ width: 100%; height: 40px; line-height: 40px; text-align: center; cursor: pointer;}.pageContent>div{ cursor: pointer; height: 30px;}.firstPage,.lastPage{ width: 60px;}.firstPage,.lastPage,.showPage{ background:rgb(67, 133, 255); color: #fff; font-size: 15px; line-height: 30px; text-align: center; border-radius: 4px;}.showPage{ width: 40px;}.prevPage,.nextPage{ height: 30px; width: 50px; border: 1px solid #ccc; border-radius: 4px; background-repeat: no-repeat; background-position: center center; background-size: 20px 20px;}.prevPage{ background-image: url(’./prev.png’); }.nextPage{ background-image: url(’./next.png’);}.nowtouch{ color:#009E94}

JS代碼:

//點擊顯示選擇條數的div var showFlag = true; var numcount = 1;//默認第一頁 var dataLength =10000; $(’#dataLength’).text(dataLength); var allCount = Math.ceil(dataLength / 10); console.log(allCount); //分頁跳轉 $(’.showPage’).text(numcount) if (numcount === 1) { firstDis(true, ’not-allowed’, ’0.5’) } if (numcount === allCount) { lastDis(true, ’not-allowed’, ’0.5’) } $(’.icona’).click(function () { if (showFlag) { $(’.pageSelectShow’).css({ ’display’: ’block’ }); $(’.icona’).css({ ’background-image’: ’url(’ + ’./up.png’ + ’)’ }) showFlag = !showFlag; } else { $(’.pageSelectShow’).css({ ’display’: ’none’ }) $(’.icona’).css({ ’background-image’: ’url(’ + ’./down.png’ + ’)’ }) showFlag = !showFlag; } }) //點擊選擇條數 // $(’.pageSelectShow li’).click(function (e) { console.log(e.target.innerHTML) var countLength = e.target.innerHTML for(var i = 0; i < countLength.length;i++){ console.log(countLength[i]) } $(’.numSelect’).text($(this).data(’num’)); allCount = Math.ceil(dataLength / e.target.dataset.num); if(allCount == 1){ firstDis(true, ’not-allowed’, ’0.5’); lastDis(true, ’not-allowed’, ’0.5’) }else{ firstDis(true, ’not-allowed’, ’0.5’) lastDis(false, ’pointer’, ’1’) } $(this).addClass(’nowtouch’).siblings().removeClass(’nowtouch’) $(’.pageSelectShow’).css({ ’display’: ’none’ }) $(’.icona’).css({ ’background-image’: ’url(’ + ’./down.png’ + ’)’ }) }) //點擊首頁 $(’.firstPage’).click(function () { numcount = 1; $(’.showPage’).text(numcount); firstDis(true, ’not-allowed’, ’0.5’) lastDis(false, ’pointer’, ’1’) }) //點擊上一頁 $(’.prevPage’).click(function () { var prevNum = Number($(’.showPage’).text()); prevNum--; $(’.showPage’).text(prevNum); if (prevNum == numcount) { firstDis(true, ’not-allowed’, ’0.5’) } else { lastDis(false, ’pointer’, ’1’) } }) //點擊下一頁 $(’.nextPage’).click(function () { var prevNum = Number($(’.showPage’).text()); prevNum++ firstDis(false, ’pointer’, ’1’) $(’.showPage’).text(prevNum); if (prevNum == allCount) { lastDis(true, ’not-allowed’, ’0.5’) } else { lastDis(false, ’pointer’, ’1’) } }) //點擊尾頁 $(’.lastPage’).click(function () { numcount = allCount $(’.showPage’).text(allCount); firstDis(false, ’pointer’, ’1’) lastDis(true, ’not-allowed’, ’0.5’) }) //當頁碼為1,禁止點擊的函數 function firstDis(boolVal, cursorVal, opacityVal) { $(’.firstPage’).attr(’disabled’, boolVal); $(’.firstPage’).css({ ’cursor’: cursorVal, ’opacity’: opacityVal }) $(’.prevPage’).attr(’disabled’, boolVal); $(’.prevPage’).css({ ’cursor’: cursorVal, ’opacity’: opacityVal }) } //當頁碼為20,禁止點擊的函數 function lastDis(boolVal, cursorVal, opacityVal) { $(’.lastPage’).attr(’disabled’, boolVal); $(’.lastPage’).css({ ’cursor’: cursorVal, ’opacity’: opacityVal }) $(’.nextPage’).attr(’disabled’, boolVal); $(’.nextPage’).css({ ’cursor’: cursorVal, ’opacity’: opacityVal }) } //鍵盤事件 $(’#goPageInp’).on(’keydown’, function (e) { if (e.keyCode == 13) { var vals = e.target.value; console.log(Number(vals)); $(this).blur(); if(Number(vals) && Number(vals) <=allCount ){ $(’.showPage’).text(vals); if (vals == allCount) { firstDis(false, ’pointer’, ’1’) lastDis(true, ’not-allowed’, ’0.5’) } if (vals == numcount) { lastDis(false, ’pointer’, ’1’) firstDis(true, ’not-allowed’, ’0.5’) } e.target.value = ’’ }else{ alert(’輸入錯誤’); e.target.value = ’’ } }})

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 欧美成人精品第一区 | 欧美一级淫片吊带丝袜 | 亚洲美女色在线欧洲美女 | 国产精品久久久久无毒 | 亚洲欧美日韩在线精品2021 | 欧美a级完整在线观看 | 高清欧美一区二区三区 | 亚洲人成亚洲精品 | yy毛片| 1024cao社区榴地址一地址二 | 青草国产精品久久久久久 | 国产爱v| 免费影院| 日韩中文字幕在线免费观看 | 一级黄色短视频 | 国产大尺度吃奶无遮无挡 | 国产美女一区 | 欧美一级色片 | 国产免费福利体检区久久 | 亚洲第一免费 | 久草在线资源福利站 | 欧洲美女大片免费播放器视频 | 亚洲精品一区亚洲精品 | 尤物精品在线观看 | 国产精品视频第一页 | 久久久国产精品福利免费 | 免费一级网站 | 手机在线国产视频 | 亚洲和欧美毛片久久久久 | 国产精品免费视频一区一 | 国产精品久久国产精品99 | 一级a级国产不卡毛片 | 无码中文字幕乱在线观看 | 国产成人精品免费 | xxxxxxhd日本d| 欧美一区二区三区在线观看不卡 | 狠狠色婷婷七月色综合 | 精品欧美日韩一区二区 | 老司机成人免费精品视频 | 精品三级久久久久久久电影 | 国产精品你懂的 |