<script language="javascript"> var obj, j; var page = 0; var nowPage = 1//当前页 var listNum = 10;//每页显示<ul>数 var listNum=3; var PagesLen;//总页数 var PageNum = 6;//分页链接接数(5个) var PageNum=4; onload = function () { obj = document.getElementById("www_zzjs_net").getElementsByTagName("li"); j = obj.length PagesLen = Math.ceil(j / listNum); upPage(0) } function upPage(p) { nowPage = p obj = document.getElementById("www_zzjs_net").getElementsByTagName("li"); j = obj.length PagesLen = Math.ceil(j / listNum); //内容变换 全球变化科学研究数据出版系统网站 hei'h for (var i = 0; i < j; i++) { obj[i].style.display = "none" } for (var i = p * listNum; i < (p + 1) * listNum; i++) { if (obj[i]) obj[i].style.display = "block" } strW = '<hr style="width:100%;margin-left:.5%;border:0;background-color:#04ADF3;height:1px;" />' strA = '<span style="float:left;margin-left:10%;">共</span>' + PagesLen + '<span>页</span>' strB = '<span>,当前为第</span>' + (nowPage + 1) + '<span>页</span>' strD = '<span>,每页10条</span>' strF = '<span>,共</span>' + j + '条数据' strS = '<a href="###" onclick="upPage(0)" style="margin-left:20%;">首页</a>' strT = '<a href="###" onclick="upPage(' + (nowPage - 1) + ')" style="margin-left:1%;">上一页</a>' var PageNum_2 = PageNum % 2 == 0 ? Math.ceil(PageNum / 2) + 1 : Math.ceil(PageNum / 2) var PageNum_3 = PageNum % 2 == 0 ? Math.ceil(PageNum / 2) : Math.ceil(PageNum / 2) + 1 var strC = "", startPage, endPage; if (PageNum >= PagesLen) { startPage = 0; endPage = PagesLen - 1; } else if (nowPage < PageNum_2) { startPage = 0; endPage = PagesLen - 1 > PageNum ? PageNum : PagesLen - 1; } //首页 else { startPage = nowPage + PageNum_3 >= PagesLen ? PagesLen - PageNum - 1 : nowPage - PageNum_2 + 1; var t = startPage + PageNum; endPage = t > PagesLen ? PagesLen - 1 : t } for (var i = startPage; i <= endPage; i++) { if (i == nowPage) strC += '<a href="###" style="margin-left:0.8%;color:red;font-weight:700;" onclick="upPage(' + i + ')">' + (i + 1) + '</a>' else strC += '<a href="###" style="margin-left:0.8%;" onclick="upPage(' + i + ')">' + (i + 1) + '</a> ' } strU = '<a href="###" onclick="upPage(' + (nowPage + 1) + ')" style="margin-left:1%;">下一页</a>' strE = '<a href="###" onclick="upPage(' + (PagesLen - 1) + ')" style="margin-left:1%;">尾页</a>' strG = '<input type="text" value="1" style="width:4%;height:.8%;margin-left:1%;margin-bottom:.4%;">' '<a ' + (i + 1) + '</a> ' strK = '<button class="" value="go" style="width:5%;height:22px;padding-top:1px;margin-left:1%;margin-bottom:.4%;">go</button>' document.getElementById("changpage").innerHTML = strW + strA + strB + strD + strF + strS + strT + strC + strU + strE; } </script>
难于阅读 。大量字符拼接
老师没叫你用数组吗?
定义一个数组 把字符串push进去 最后 转化字符串
拼a标签的时候,如果当前页是第一页或者最后一页,就把href值设置为"javascript:void(0);"
再写一个函数 接收参数nowpage 函数内对nowpage判定 处理的你的问题。 然后让这个函数在document.ready时执行一次、每次触发upPage()时都执行一次
//这个是我写好的代码,你试一下
<table width="1175px" border="1" cellspacing="0" align="center" style="background-color: #E5F5FF;TABLE-LAYOUT: fixed" cellpadding="0">
<tr>
<td colspan="17" align="center"style="border: 1px solid #73C2FF; font-family: 宋体; font-size: 19px;">总共查询到${totalRecord}条记录,每页显示${pageSize}条,共${totalPage}页,当前是第${pageIndex}页。
<%
if( request.getAttribute("pageIndex")!=null){
Integer iPageIndex = (Integer) request.getAttribute("pageIndex");
if( request.getAttribute("totalPage")!=null){
Integer iTotalPage = (Integer) request.getAttribute("totalPage");
if (iPageIndex > 1) {
%> <a
href="<%=request.getContextPath()%>/Xmb/Xmb_execute.action?pageIndex=1&pageSize=${pageSize}&aa=${aa}&bb=${bb}">第一页</a>
<a
href="<%=request.getContextPath()%>/Xmb/Xmb_execute.action?pageIndex=${pageIndex - 1}&pageSize=${pageSize}&aa=${aa}&bb=${bb}">上一页</a>
<%
}
if (iPageIndex < iTotalPage) {
%> <a
href="<%=request.getContextPath()%>/Xmb/Xmb_execute.action?pageIndex=${pageIndex + 1}&pageSize=${pageSize}&aa=${aa}&bb=${bb}">下一页</a>
<a
href="<%=request.getContextPath()%>/Xmb/Xmb_execute.action?pageIndex=${totalPage}&pageSize=${pageSize}&aa=${aa}&bb=${bb}">最后一页</a>
<%
}
}
}
%>
<form id="frmGoPage" name="frmGoPage" method="post"
action="<%=request.getContextPath()%>/Xmb/Xmb_execute.action?pageSize=${pageSize}&aa=${aa}&bb=${bb}">
第 <input name="pageIndex" type="text" id="pageIndex"
style="height: 25px; width: 40px;" value="${pageIndex}" /> 页
<input type="submit" style="height: 25px;" value="Go" />
</form>
</td>
</tr>
</table>
你的代码太乱了,根本没心思看。我可以给你个建议,如果你自己实在解决不了根本问题:
如果 第一页
隐藏 第一页按钮
如果 最后一页
隐藏 最后一页按钮