首页 > 代码库 > 封装的分页jq
封装的分页jq
(function ($) {$.fn.page = function (options) {var defaults = {divid: "pagediv",count: 10, //remove or hidepageindex: 1,callback: function (pageindex) { }};var html = "";var opts = $.extend(defaults, options);opts.callback(1);var div = $("#" + opts.divid);var a = [];//根据当前页数判断上一页是否可以点击if (opts.pageindex == 1) {html = html + "<a href=http://www.mamicode.com/"#\" class=\"prev unclick\">上一页</a>";} else {html = html + "<a href=http://www.mamicode.com/"#\" class=\"prev\">上一页</a>";}for (var i = 0; i < opts.count; i++) {//判断显示页码的样式if ((i + 1) == opts.pageindex) {html = html + "<a href=http://www.mamicode.com/"javascript:void(0)\" style=\"background:#999\">" + (i + 1) + "</a>"} else {html = html + "<a href=http://www.mamicode.com/"javascript:void(0)\">" + (i + 1) + "</a>";}}//根据当前页数判断上一页是否可以点击if (opts.pageindex == opts.count) {html = html + "<a href=http://www.mamicode.com/"javascript:void(0)\" class=\"next unclick\">下一页</a>";} else {html = html + "<a href=http://www.mamicode.com/"javascript:void(0)\" class=\"next\">下一页</a>";}$("#" + opts.divid).html(html);$("#" + opts.divid + " a").not($(".prev")).not(".next").click(function () {$(this).css("background", "#999")$(this).siblings().removeAttr("style");opts.pageindex = $(this).html();if (opts.pageindex != 1) {$(".prev").removeClass("unclick");} else {$(".prev").addClass("unclick");}if (opts.pageindex == opts.count) {$(".next").addClass("unclick");} else {$(".next").removeClass("unclick");}opts.callback(opts.pageindex);})$(".prev").click(function () {$("#" + opts.divid + " a").eq(opts.pageindex).removeAttr("style");if (opts.pageindex == 1) {opts.pageindex == 1} else {opts.pageindex = opts.pageindex - 1;}$("#" + opts.divid + " a").eq(opts.pageindex).css("background", "#999");if (opts.pageindex != 1) {$(".prev").removeClass("unclick");} else {$(".prev").addClass("unclick");}if (opts.pageindex == opts.count) {$(".next").addClass("unclick");} else {$(".next").removeClass("unclick");}opts.callback(opts.pageindex);});$(".next").click(function () {$("#" + opts.divid + " a").eq(opts.pageindex).removeAttr("style");if (opts.pageindex == 10) {opts.pageindex == 10} else {opts.pageindex = parseInt(opts.pageindex) + 1;}$("#" + opts.divid + " a").eq(opts.pageindex).css("background", "#999");if (opts.pageindex != 1) {$(".prev").removeClass("unclick");} else {$(".prev").addClass("unclick");}if (opts.pageindex == opts.count) {$(".next").addClass("unclick");} else {$(".next").removeClass("unclick");}opts.callback(opts.pageindex);});}})(jQuery);
封装的分页jq
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。