jquery分頁插件

jquery.mypagination.js 文件:



/* *

*?
* jquery分頁插件
* 1.0 ?zheng 2014-03-18?
* 1.1 ?兼容url包含#號地址,GoToPage可以指定錨點(特殊需求)2014-04-10 09:00:34
* 1.2 ?可以配置分頁條列出頁面數
* 1.3 ?增加了頁面碼跳轉功能
* ?$('#mypage').scPagination(555, {
* ? ? ? ? ? ? ?pageSize: 10,//每頁顯示的記錄條數
* ? ? ? ? ? myPagerCount:10,//分頁條顯示的頁面個數
* ? ? ? ? ? ? ?callback: function (page) {
* ? ? ? ? ? ? ? ? ?alert("選擇了頁碼"+page);
* ? ? ? ? ? ? ?}
* ? ? ? ? ?});
*/



$.fn.scPagination = function (totalProperty, opts) {
? ? opts = $.extend({
? ? ? ? pageSize: 10,
myPagerCount:10,
? ? ? ? callback: function () {
? ? ? ? }
? ? }, opts || {});
? ? return this.each(function () {
? ? ? ? function numPages() {
? ? ? ? ? ? return Math.ceil(totalProperty / opts.pageSize);
? ? ? ? }




? ? ? ? function selectPage(page) {
? ? ? ? ? ? return function () {
? ? ? ? ? ? ? ? currPage = page;
? ? ? ? ? ? ? ? if (page < 1) currPage = 1;
? ? ? ? ? ? ? ? if (page >= numPages()) currPage = numPages();
? ? ? ? ? ? ? ? render();
? ? ? ? ? ? ? ? opts.callback(currPage);
? ? ? ? ? ? }
? ? ? ? }


? ? ? ? function render() {
? ? ? ? ? ? var html = '<div class="Page">'
?+ '<div>[共<span class="Total">' + totalProperty + '</span>條]</div>'
?+ '<a id="page-first" href="javascript:void(0);">首頁</a>'
?+ '<a id="page-prev" href="javascript:void(0);">上頁</a>';
var fistPage=1;
var lastPage=numPages();
if(currPage>Math.ceil((opts.myPagerCount-1)/2))
{
fistPage=currPage-Math.ceil((opts.myPagerCount-1)/2);
}
if(fistPage>numPages()-opts.myPagerCount+1)
{
fistPage=numPages()-opts.myPagerCount+1;
}
if(fistPage<1)fistPage=1;
lastPage=opts.myPagerCount+fistPage-1;
if(lastPage>numPages())lastPage=numPages();


? ? ? ? ? ? for (i = fistPage; i <= lastPage; i++) {
? ? ? ? ? ? ? ? //if (currPage + i <= numPages() && currPage + i > 0) {
? ? ? ? ? ? ? ? ? ? html += '<a href="javascript:void(0);" class="NumPage">' + i + '</a>';
? ? ? ? ? ? ? ?// }
? ? ? ? ? ? }


? ? ? ? ? ? html += '<a id="page-next" href="javascript:void(0);">下頁</a>'
? ? ? ? ? ? ? ? ?+ '<a ?id="page-last" href="javascript:void(0);">尾頁</a>'
+ '<input id="txtGoTo" class="page-num"/><a id="btnGoTo" href="javascript:void(0);">GO</a>'
? ? ? ? ? ? ? ? ?+ '</div>';


? ? ? ? ? ? if (currPage > 0) {


? ? ? ? ? ? }
? ? ? ? ? ? if (currPage < numPages()) {


? ? ? ? ? ? }
? ? ? ? ? ? panel.empty();
? ? ? ? ? ? panel.append(html);
? ? ? ? ? ? $('#page-first', panel)
? ? ? ? ? ? ? ? .bind('click', selectPage(1));
? ? ? ? ? ? $('#page-prev', panel)
? ? ? ? ? ? ? ? .bind('click', selectPage(currPage - 1));
? ? ? ? ? ? $('#page-next', panel)
? ? ? ? ? ? ? ? .bind('click', selectPage(currPage + 1));
? ? ? ? ? ? $('#page-last', panel)
? ? ? ? ? ? ? ? .bind('click', selectPage(numPages()));?

? ? ? ? ? ? $('.NumPage').each(function () {
? ? ? ? ? ? ? ? $(this).bind('click', selectPage(parseInt($(this).text())));
? ? ? ? ? ? ? ? if (parseInt($(this).text()) == (currPage)) {


? ? ? ? ? ? ? ? ? ? $(this).attr('class', 'Selected');
? ? ? ? ? ? ? ? }
? ? ? ? ? ? });







? ? ? ? ? ? $('input.page-num', panel)
? ? ? ? ? ? ? ? .val(currPage)
? ? ? ? ? ? ? ? .change(function () {
? ? ? ? ? ? ? ? ? ? selectPage($(this).val())();
? ? ? ? ? ? ? ? });


$('#btnGoTo',panel)
.bind('click',?
function()
{
var goPage=parseInt($('#txtGoTo').val());
selectPage(goPage)();
}
);?






? ? ? ? ? ? if (request("pageIndex") != "") {
? ? ? ? ? ? ? ? $('.Selected').each(function () {


? ? ? ? ? ? ? ? ? ? $(this).attr('class', 'NumPage');


? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? $('.NumPage').each(function () {
? ? ? ? ? ? ? ? ? ? if (parseInt($(this).text()) == parseInt(request("pageIndex"))) {
? ? ? ? ? ? ? ? ? ? ? ? $(this).attr('class', 'Selected');
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? var currPage = 1;
? ? ? ? if (request("pageIndex") != "") {
? ? ? ? ? ? currPage = parseInt(request("pageIndex"));
? ? ? ? }
? ? ? ? var panel = $(this);
? ? ? ? render();


? ? ? ? function request(paras) {
? ? ? ? ? ? var url = location.href;
? ? ? ? ? ? var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
? ? ? ? ? ? var paraObj = {}
? ? ? ? ? ? for (i = 0; j = paraString[i]; i++) {
? ? ? ? ? ? ? ? paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
? ? ? ? ? ? }
? ? ? ? ? ? var returnValue = paraObj[paras.toLowerCase()];
? ? ? ? ? ? if (typeof (returnValue) == "undefined") {
? ? ? ? ? ? ? ? return "";
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? return returnValue;
? ? ? ? ? ? }
? ? ? ? }


? ? });
}




//獲取url參數 request("ID")
function request(paras) {
? ? var url = location.href;
? ? var splitChar = /[&#]/;//設置分隔字符
? ? var paraString = url.substring(url.indexOf('?') + 1, url.length).split(splitChar);
? ? var paraObj = {}
? ? for (i = 0; j = paraString[i]; i++) {
? ? ? ? paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
? ? }
? ? var returnValue = paraObj[paras.toLowerCase()];
? ? if (typeof (returnValue) == "undefined") {
? ? ? ? return "";
? ? } else {
? ? ? ? return returnValue;
? ? }
}


function GoToPage(page, anchor) {


? ? var oUrl = this.location.href.toString();
? ? if (anchor && oUrl.indexOf("#" + anchor) > 0) {
? ? ? ? oUrl=oUrl.replace("#" + anchor, "");
? ? }
? ? var re = eval('/(pageIndex=)([^&|#]*)/gi');
? ? var nUrl = oUrl.replace(re, 'pageIndex=' + page);
? ? if (request("pageIndex") == "") {
? ? ? ? if (oUrl.indexOf("?") <= 0) {
? ? ? ? ? ? nUrl = nUrl + "?pageIndex=" + page;
? ? ? ? }
? ? ? ? else {
? ? ? ? ? ? nUrl = nUrl + "&pageIndex=" + page;
? ? ? ? }
? ? }
? ? if (anchor && oUrl.indexOf("#" + anchor) < 0) {//鏈接到錨點
? ? ? ? anchor = anchor.replace('#', '');
? ? ? ? nUrl = nUrl + "#" + anchor;
? ? }
? ? this.location = nUrl;
}




function replaceParamVal(paramName, replaceWith) {
? ? var oUrl = this.location.href.toString();
? ? var re = eval('/(' + paramName + '=)([^&|#]*)/gi');
? ? var nUrl = oUrl.replace(re, paramName + '=' + replaceWith);
? ? this.location = nUrl;
}




/***用到的樣式 為了方便直接寫在了此處**/
document.write(" <style type=\"text/css\">");
document.write("/*分頁開始*/");
document.write(".Page");
document.write("{");
document.write(" height: 26px;");
document.write("}");


document.write(" .Page div");
document.write(" {");
document.write(" display: inline-block;");
document.write(" zoom: 1;");
document.write(" font-size: 14px;");
document.write(" }");


document.write(" .Page .Total");
document.write(" {");
document.write(" color: #cc0000;");
document.write(" }");


document.write(" .Page a");
document.write(" {");
document.write(" padding: 4px 5px;");
document.write(" height: 14px;");
document.write(" line-height: 14px;");
document.write(" font-size: 14px;");
document.write(" border: 1px solid #d5d5d5;");
document.write(" margin: 0px 5px;");
document.write(" display: inline-block;");
document.write(" }");


document.write(" .Page a:hover");
document.write(" {");
document.write(" text-decoration: underline;");
document.write(" border-color: #cc0000;");
document.write(" }");


document.write(" .Page .Selected");
document.write(" {");
document.write(" background: #cc0000;");
document.write(" border-color: #cc0000;");
document.write(" color: #ffffff;");
document.write(" display: inline-block;");
document.write(" zoom: 1;");
document.write(" }");
document.write(" .Page input");
document.write(" {");
document.write(" width:40px;");
document.write(" overflow-x:visible;");
document.write(" padding: 4px 5px;");
document.write(" height: 14px;");
document.write(" line-height: 14px;");
document.write(" font-size: 14px;");
document.write(" border: 1px solid #d5d5d5;");
document.write(" margin: -3px 0px 0px 5px;");
document.write(" display: inline-block;");
document.write(" }");
document.write("/*分頁結束*/");

document.write(" </style>");




test.html 測試文件:


<head> ?
? ? <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> ?
? ? <script type="text/javascript" src="jquery.mypagination.js"></script> ?
</head> ?

?<div id="mypage" class="Pagination" style="margin-bottom: 0px;"></div>
?<script> ?
? ? ? ? $(document).ready(function(){ ?
? ? ? ? ? ? $('#mypage').scPagination(555,{
pageSize:20,
myPagerCount:10,
? ? ? ? ? ? ? ? callback:function(page){ ?
? ? ? ? ? ? ? ? ? ? alert(page); ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? }); ?
? ? ? ? }); ?
?</script> ?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/286853.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/286853.shtml
英文地址,請注明出處:http://en.pswp.cn/news/286853.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android之如何分析手機系統相冊圖片和視頻刪除后保存的位置

1 需求 需要獲取各種型號手機系統相冊圖片和視頻刪除后保存的位置 2 分析 1)我們可以通過在sdcard目錄下進行相關查找文件夾關鍵字,對 "cycle"或者"trash"或者*galle*進行忽略大小寫模糊查詢都有文件夾 find . -iname *cycle* find . -iname *trash*…

WPF 實現水珠效果按鈕組

本文經原作者授權以原創方式二次分享&#xff0c;歡迎轉載、分享。原文作者&#xff1a;普通的地球人原文地址&#xff1a;https://www.cnblogs.com/tsliwei/p/8041928.html相關知識這部分基本就是廢話,網上都能找到,我只不過是整理了以下.建議先不看,用到的時候可以回來看看貝…

GetDisplayName 獲取枚舉的顯示值

item.State.GetDisplayName(), 轉載于:https://www.cnblogs.com/zhongku/p/4944315.html

組策略管理——軟件限制策略(4)

編寫軟件限制規則 在前面幾篇文章中講了軟件限制規則的基本概念&#xff0c;現在就來學習如何編寫自定義軟件限制策略。 編寫規則應遵循的原則 首先&#xff0c;需要大家注意的是&#xff0c;軟件限制策略應本著方便、安全、實用的原則來編寫。限制規則靈活方便&#xff0c;自定…

我使用 html 反向輸出自己打自己(7)

作者簡介 作者名&#xff1a;1_bit 簡介&#xff1a;CSDN博客專家&#xff0c;2020年博客之星TOP5&#xff0c;藍橋簽約作者。15-16年曾在網上直播&#xff0c;帶領一批程序小白走上程序員之路。歡迎各位小白加我咨詢我相關信息&#xff0c;迷茫的你會找到答案。 目錄 HTML基…

甘肅省普通高等學校高職(專科)升本科考試英語科考試大綱(試行)

甘肅省普通高等學校高職&#xff08;專科&#xff09;升本科考試英語科考試大綱&#xff08;試行&#xff09; 一、考試目的 全面考核普通高等學校高職&#xff08;專科&#xff09;應屆畢業生英語課程是否達到教學大綱所規定的目標&#xff08;領會式掌握3500單詞&#xff0c…

256種編程語言大薈萃

本文是碼農網原創翻譯&#xff0c;轉載請看清文末的轉載要求&#xff0c;謝謝合作&#xff01; 雙休日常常意味著很多休息時間。與其懶洋洋地坐在那里玩游戲&#xff0c;為何不學點新知識武裝自己&#xff1f;本文中不會特定推薦哪種編程語言&#xff0c;但是會提供基于GitHub上…

java 獲取系統當前時間

Calendar ca Calendar.getInstance(); int year ca.get(Calendar.YEAR);//獲取年份 int monthca.get(Calendar.MONTH);//獲取月份 int dayca.get(Calendar.DATE);//獲取日 int minuteca.get(Calendar.MINUTE);//分 int hourca.get(Calendar.HOUR)…

Android之最簡單的遍歷某個目錄下的所有文件(遞歸)

1、問題 遍歷某個目錄下的所有問題文件 2、代碼實現 fun getRecoverTrashFile(path: String) {if (TextUtils.isEmpty(path))returntry {var file File(path)if (file null || !file.exists()) {return}var files file.listFiles()if (files null || files.size < 0) {…

Castle.DynamicProxy攔截器

在asp.net mvc或asp.net miniapi中&#xff0c;有過濾器&#xff0c;可以在請求前或后增加一層&#xff0c;達到驗證&#xff0c;過濾等作用&#xff0c;如果在Service的方法前后加一層呢&#xff1f;這里介紹一下Castle.DynamicProxy的用法。首先引入Castle.Core實現代碼相對輕…

甘肅省普通高等學校高職(專科)升本科考試計算機科考試大綱(試行)

甘肅省普通高等學校高職&#xff08;專科&#xff09;升本科考試計算機科考試大綱&#xff08;試行&#xff09; 一、考試目的及要求 全面考核普通高等學校高職&#xff08;專科&#xff09;應屆畢業生計算機應用能力是否達到教學大綱所規定的要求。所有考生計算機基礎知識必須…

Android選項切換條SHSegmentControl

&#xfeff;&#xfeff;Android選項切換條SHSegmentControl SHSegmentControl是github上一個開源的選項切換條&#xff0c;其樣式如圖所示&#xff1a; SHSegmentControl在github上的項目主頁地址&#xff1a;https://github.com/7heaven/SHSegmentControl SHSegmentControl…

從零開始編寫自己的C#框架(14)——T4模板在邏輯層中的應用(三)

原本關于T4模板原想分5個章節詳細解說的&#xff0c;不過因為最近比較忙&#xff0c;也不想將整個系列時間拉得太長&#xff0c;所以就將它們整合在一塊了&#xff0c;可能會有很多細節沒有講到&#xff0c;希望大家自己對著代碼與模板去研究。 本章代碼量會比較大&#xff0c;…

趕緊3分鐘學完15分鐘的內容我要出去玩(8)

作者簡介 作者名&#xff1a;1_bit 簡介&#xff1a;CSDN博客專家&#xff0c;2020年博客之星TOP5&#xff0c;藍橋簽約作者。15-16年曾在網上直播&#xff0c;帶領一批程序小白走上程序員之路。歡迎各位小白加我咨詢我相關信息&#xff0c;迷茫的你會找到答案。 目錄 HTML基…

Android之獲取到音視頻的時長后按格式(00:00或者00:00:00)顯示

1 需求 我們獲取到了本地視頻時長(秒為單位),然后需要按照如下格式顯示 沒有到小時的時長如下格式 00:00 有到小時的時長如下格式 00:00:00 2 代碼實現 /*** 可以顯示小時*/fun getDateStr(ms: Long): String? {val ss = 1val mi = ss * 60val hh = mi * 60val dd = …

Hello Playwright:(5)查找元素

操作瀏覽器歸根到底就是和頁面進行交互&#xff0c;那么必不可少的操作就是查找頁面上的元素。因此我們需要熟練掌握Locator 定位器。在上一節我們講過&#xff0c;可以使用Page.Locator(selector, options)方法創建定位器&#xff0c;而如何定位到元素則取決于selector 選擇器…

RxSwift 之官方文檔

RxSwift 官方文檔結構 Introduction:SubjectsTransforming ObservablesFiltering ObservablesCombining ObservablesError Handing OperatorsObservable Utility OperatorsConditional and Boolean OperatorsMathematical and Aggregate OperatorsConnectable Observable Opera…

SQL一鍵備份用戶數據庫

大家都知道&#xff0c;Ms Sql 有自動備份的功能&#xff0c;但如果由于某種原因不能自動備份&#xff0c;或者我們想手動備份的話&#xff0c;就可以用下邊的sql語句來執行備份。 --------------------代碼開始------------- USE [master]------刪除舊數據-------------------…

2019年甘肅省普通高等學校高職(專科)升本科考試招生工作實施辦法

2019年甘肅省普通高等學校高職&#xff08;專科&#xff09;升本科考試招生工作實施辦法 2019年甘肅省普通高等學校高職&#xff08;專科&#xff09;升本科考試招生工作實施辦法 根據教育部有關規定及要求&#xff0c;結合我省實際&#xff0c;為確保普通高等學校高職&#x…

HTML基礎之bit哥的反客為主之道(9)

作者簡介 作者名&#xff1a;1_bit 簡介&#xff1a;CSDN博客專家&#xff0c;2020年博客之星TOP5&#xff0c;藍橋簽約作者。15-16年曾在網上直播&#xff0c;帶領一批程序小白走上程序員之路。歡迎各位小白加我咨詢我相關信息&#xff0c;迷茫的你會找到答案。 目錄 HTML基…