十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
小編這次要給大家分享的是jQuery如何實現(xiàn)分頁插件,文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比隰縣網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式隰縣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋隰縣地區(qū)。費用合理售后完善,10年實體公司更值得信賴。
本文實例講述了jQuery實現(xiàn)的分頁插件。分享給大家供大家參考,具體如下:
呈現(xiàn)
html文件
Insert title here
css文件
@charset "UTF-8"; /*分頁所在的div*/ .devidePage{ margin-top:300px; margin-left: 400px; height: 50px; width: 800px; /* background: gray; */ } /*顯示頁數(shù)的div*/ .pages{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; } /*首頁*/ .theFirstPage{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; } /*末頁*/ .theLastPage{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; } /*上一頁*/ .prePage{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; } /*下一頁*/ .nextPage{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; } /*當(dāng)前頁數(shù)*/ .currentPage{ float:left; margin-left:2px; height:50px; width:100px; background: #EEEEEE; text-align:center; line-height:50px; } /*總頁數(shù)*/ .pageNums{ float:left; margin-left:2px; height:50px; width:100px; background: #EEEEEE; text-align:center; line-height:50px; } /*輸入頁數(shù)*/ .jump{ float:left; margin-left:2px; height:48px; width:50px; border:0.5px solid #EEEEEE; } /*跳轉(zhuǎn)*/ .jumpClick{ float:left; margin-left:2px; height:50px; width:50px; background: #EEEEEE; text-align:center; line-height:50px; cursor:pointer; }
js文件
/** * 俠 2018-8-15 */ function loadAll() { var theFirstPage = "首頁"; var prePage = "上一頁"; var pagess = "1" + "2" + "3" + "4" + "5"; var nextPage = "下一頁"; var theLastPage = "末頁"; var currentPages = "第1頁"; var pageNums = "共" + pages + "頁"; var jump = ""; var jumpClick = "跳轉(zhuǎn)"; $("#pages").html(theFirstPage + prePage + pagess + nextPage + theLastPage + currentPages + pageNums + jump + jumpClick); } loadAll(); function defultBackground() { $("#page_1").css("background", "#66b2ff"); //配置選中顏色 } defultBackground(); function changeBackground() { $(".pages").css("background", "#EEEEEE"); //配置默認(rèn)顏色 for (var i = 0; i < 5; i++) { if ($("#page_" + (i + 1)).text() == $("#currentPage").text().split("第")[1] .split("頁")[0]) { $("#page_" + (i + 1)).css("background", "#66b2ff"); //配置選中顏色 break; } } } function theFirstPage(){ $('#currentPage').html("第" + 1 + "頁"); $("#page_1").html(1); $("#page_2").html(2); $("#page_3").html(3); $("#page_4").html(4); $("#page_5").html(5); changeBackground(); getData(getCurrentPageNum()); } function theLastPage(){ $('#currentPage').html("第" + pages + "頁"); $("#page_1").html(pages-4); $("#page_2").html(pages-3); $("#page_3").html(pages-2); $("#page_4").html(pages-1); $("#page_5").html(pages); changeBackground(); getData(getCurrentPageNum()); } function changePage(id) { var pagenum = parseInt($("#" + id).text()) - 1; $('#currentPage').html("第" + $("#" + id).text() + "頁"); if ((id.split("_")[1] == 1) && (parseInt($("#" + id).text()) > 1)) { $("#page_1").html(parseInt($("#page_1").text()) - 1); $("#page_2").html(parseInt($("#page_2").text()) - 1); $("#page_3").html(parseInt($("#page_3").text()) - 1); $("#page_4").html(parseInt($("#page_4").text()) - 1); $("#page_5").html(parseInt($("#page_5").text()) - 1); } if ((id.split("_")[1] == 5) && (parseInt($("#" + id).text()) < pages)) { $("#page_1").html(parseInt($("#page_1").text()) + 1); $("#page_2").html(parseInt($("#page_2").text()) + 1); $("#page_3").html(parseInt($("#page_3").text()) + 1); $("#page_4").html(parseInt($("#page_4").text()) + 1); $("#page_5").html(parseInt($("#page_5").text()) + 1); } changeBackground(); getData(getCurrentPageNum()); } function prePage() { var currentPageNumStr = $("#currentPage").text().split("第")[1].split("頁")[0]; var currentPageNum = parseInt(currentPageNumStr); if (currentPageNum > 1) { var toPageNum = currentPageNum - 1; $("#currentPage").html("第" + toPageNum + "頁"); if ((currentPageNum > 1) && ($("#page_1").text() != 1)) { $("#page_1").html(parseInt($("#page_1").text()) - 1); $("#page_2").html(parseInt($("#page_2").text()) - 1); $("#page_3").html(parseInt($("#page_3").text()) - 1); $("#page_4").html(parseInt($("#page_4").text()) - 1); $("#page_5").html(parseInt($("#page_5").text()) - 1); } changeBackground(); getData(getCurrentPageNum()); } else { } } function nextPage() { var currentPageNumStr = $("#currentPage").text().split("第")[1].split("頁")[0]; var currentPageNum = parseInt(currentPageNumStr); if (currentPageNum < pages) { var toPageNum = currentPageNum + 1; $("#currentPage").html("第" + toPageNum + "頁"); if (currentPageNum >= 5 && ($("#page_5").text() != pages)) { $("#page_1").html(parseInt($("#page_1").text()) + 1); $("#page_2").html(parseInt($("#page_2").text()) + 1); $("#page_3").html(parseInt($("#page_3").text()) + 1); $("#page_4").html(parseInt($("#page_4").text()) + 1); $("#page_5").html(parseInt($("#page_5").text()) + 1); } changeBackground(); getData(getCurrentPageNum()); } else { } } function jump() { var numstr = $("#jump").val(); var num = parseInt(numstr); if ((num < 1) || (num > pages)) { alert("輸入不合法"); $("#jump").val(1); } else { $("#currentPage").html("第" + num + "頁"); if (num >= 5) { $("#page_5").html(num); $("#page_4").html(num - 1); $("#page_3").html(num - 2); $("#page_2").html(num - 3); $("#page_1").html(num - 4); } else { if (num = 4) { $("#page_5").html(num + 1); $("#page_4").html(num); $("#page_3").html(num - 1); $("#page_2").html(num - 2); $("#page_1").html(num - 3); } if (num = 3) { $("#page_5").html(num + 2); $("#page_4").html(num + 1); $("#page_3").html(num); $("#page_2").html(num - 1); $("#page_1").html(num - 2); } if (num = 2) { $("#page_5").html(num + 3); $("#page_4").html(num + 2); $("#page_3").html(num + 1); $("#page_2").html(num); $("#page_1").html(num - 1); } if (num = 1) { $("#page_5").html(num + 4); $("#page_4").html(num + 3); $("#page_3").html(num + 2); $("#page_2").html(num + 1); $("#page_1").html(num); } } changeBackground(); getData(getCurrentPageNum()); } } function getCurrentPageNum(){ return parseInt( $("#currentPage").text().split("第")[1].split("頁")[0] ); }
看完這篇關(guān)于jQuery如何實現(xiàn)分頁插件的文章,如果覺得文章內(nèi)容寫得不錯的話,可以把它分享出去給更多人看到。