;(function ($) { $.fn.dhpageing = function (option) { var defaultmenus = {showitemnum:10,theme:'#2c73ac'}, contentbox, pagingbox, allitem, allpagenum, currentpage = 1, home, end, prev, next, skip, btn, pagingallnumbox, inputvalue if (typeof option === 'object' && !(option instanceof array)) { defaultmenus.showitemnum = option.showitemnum || 10 defaultmenus.theme = option.theme || '#2c73ac' } contentbox = this var initpaging = function (self) { var pagingstr = '
' self.after(pagingstr) //获得paging按钮的一系列对象 pagingbox = self.next() allitem = self.find('> *') allpagenum = math.ceil(allitem.length / defaultmenus.showitemnum) home = pagingbox.find('.paging_home') end = pagingbox.find('.paging_end') prev = pagingbox.find('.paging_prev') next = pagingbox.find('.paging_next') skip = pagingbox.find('.paging_skip') btn = pagingbox.find('.paging_btn') inputvalue = pagingbox.find('.paging_num') pagingallnumbox = pagingbox.find('.paging_all_num') btn.css('background', defaultmenus.theme) pagingallnumbox.html(allpagenum) inputvalue.keydown(function (e) { if (e.keycode === 13) { skiphandle() } }) } var render = function (self) { //主渲染函数 var _showitemnum = defaultmenus.showitemnum, renderitem, domfragment = document.createdocumentfragment() renderitem = allitem.slice(currentpage * _showitemnum - _showitemnum, currentpage * _showitemnum) for (var i = 0; i < renderitem.length; i++) { domfragment.appendchild(renderitem[i]) } contentbox.html($(domfragment)) inputvalue.val(currentpage) } var btnclick = function (self) { //各个按钮点击事件执行函数 btn.click(function () { if (this === home[0]) { homehandle() } else if (this === end[0]) { endhandle() } else if (this === prev[0]) { prevhandle() } else if (this === next[0]) { nexthandle() } else if (this === skip[0]) { skiphandle() } }) } var homehandle = function () { currentpage = 1 render() }, endhandle = function () { currentpage = allpagenum render() }, prevhandle = function () { currentpage-- if (currentpage < 1) { currentpage = 1 } else { render() } }, nexthandle = function () { currentpage++ if (currentpage > allpagenum) { currentpage = allpagenum } else { render() } }, skiphandle = function () { var _setcurrentpagenum = inputvalue.val() if (_setcurrentpagenum > allpagenum) { _setcurrentpagenum = allpagenum } if (_setcurrentpagenum < 1) { _setcurrentpagenum = 1 } currentpage = _setcurrentpagenum render() } initpaging(this) render(this) btnclick(this) } })(jquery);