jQuery监听用JavaScript分布函数来制作分页链接,可以省下很多html代码流量呢
(function($) { $.fn.pagination = function(pagecount, page, surl) { var $box = $(this).empty(); var shtml = '' if (pagecount <= 1) { $box.css({ 'height': 4, 'padding': 0 }); return $box } if (page == 1) shtml += '<a href="#" target="_self">«</a>'; else shtml += '<a href="' + surl.replace("$", (page - 1)) + '" target="_self">«</a>'; if (pagecount < 11) { for (var i = 1; i <= pagecount; i++) { if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>'; else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>' } } else { if (page <= 10) { for (var i = 1; i <= 10; i++) { if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>'; else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>' } } else if (pagecount - page < 10) { for (var i = pagecount - 9; i <= pagecount; i++) { if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>'; else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>' } } else { for (var i = page - 5; i < page + 5; i++) { if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>'; else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>' } } } if (page == pagecount) shtml += '<a href="#">»</a>'; else shtml += '<a target="_self" href="' + surl.replace("$", (page + 1)) + '">»</a>'; if (pagecount > 10) { shtml += '<span>跳转到 </span>'; shtml += '<input type="text" size="2" maxlength="4" value="' + page + '" />'; shtml += '<span> 页</span>' } $box.html(shtml).find('input').change(function() { var p = $(this).val(); window.location.href = surl.replace("$", p) }); return $box } })(jquery);
之后只要这么引用它就好了:$(function(){$('#page').pagination(100,1,'aaa.htm?page=$')})
上一篇:
jQuery判断对象是否存在
下一篇:
JS去掉字符串前后空格
友情提示:垃圾评论一律封号...