jsp分页 < 1 ... 3 4 5 6 7 ... 100 >

本文介绍了一个基于JavaScript的分页组件实现方法,通过计算当前页、前后页及末页等信息来动态生成分页链接。该组件能根据当前页码显示相应的页数链接,并支持跳转到指定页。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pageCount = data.pageCount;
		  	//alert("总页数: "+pageCount);
		  	currentPage = data.currentPage;
		  	//alert("当前页:"+currentPage);
		  	var prevPage = currentPage - 1;
		  	//alert("前一页: "+prevPage);
		  	var nextPage = currentPage - (-1);
		  	//alert("后一页: "+nextPage);
		  	var endPage = "";
		  	$("#paging").html("");
		  	var strHtml = "";
			if (prevPage > 0) {
				strHtml += "<li onclick='selectHistoryTask(\"before\")'><</li>";
			};
			if (currentPage != 1){
				strHtml += "<li onclick='selectHistoryTask(1)'>1</li>";
			}
			if (currentPage >= 5){
				strHtml += "<li>...</li>";
			}; 
			if (pageCount > currentPage - (-2)) {
				endPage = currentPage - (-2);
			} else {
				endPage = pageCount;
			}
			//alert("endPage:"+endPage);
			for (var i = currentPage - 2; i <= endPage; i++) {
				if (i > 0) {
					if (i == currentPage) {
						strHtml += "<li class='paginationActive' >"+i+"</li>";
					} else {
						if (i != 1 && i != pageCount) {
							strHtml += "<li onclick='selectHistoryTask("+i+")'>"+i+"</li>";
						}
					}
				}
			}
			if (currentPage - (-3) < pageCount){
				strHtml += "<li>...</li>";
			}; 
			if (currentPage != pageCount){
				strHtml += "<li onclick='selectHistoryTask("+pageCount+")'>"+pageCount+"</li>";
			}; 
			if (nextPage <= pageCount) {
				strHtml += "<li onclick='selectHistoryTask(\"next\")'>></li>";
			};
		  	$("#paging").append(strHtml);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值