JSP假分頁效果
阿新 • • 發佈:2019-02-14
<body>
<table id="t_student" border="1" cellpadding="2" cellspacing="0" style="text-align:center;width:500px">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
</tr>
</thead>
<c:forEach items="${list}" var="st">
<tr>
<td>${st.getId()}</td>
<td>${st.getName()}</td>
</tr>
</c:forEach>
</table>
<div class="gridItem" style="padding: 5px; width: 250px; float: left; text-align: left; height: 20px; font-size: 15px;" >
共有 <span id="spanTotalInfor"></span> 條記錄
當前第<span id="spanPageNum"></span>頁
共<span id="spanTotalPage"></span>頁
</div>
<div class="gridItem" style="margin-left:50px; padding: 5px; width: 400px; float: left; text-align: center; height: 20px; vertical-align: middle; font-size: 15px;">
<span id="spanFirst" >首頁</span>
<span id="spanPre">上一頁</span>
<span id="spanInput" style="margin: 0px; padding: 0px 0px 4px 0px; height:100%; ">
第<input id="Text1" type="text" class="TextBox" onkeyup="changepage()" style="height:20px; text-align: center;width:50px" />頁
</span>
<span id="spanNext">下一頁</span>
<span id="spanLast">尾頁</span>
</div>
<script type="text/javascript">
var theTable = document.getElementById("t_student");
var txtValue = document.getElementById("Text1").value;
function changepage() {
var txtValue2 = document.getElementById("Text1").value;
if (txtValue != txtValue2) {
if (txtValue2 > pageCount()) {
}
else if (txtValue2 <= 0) {
}
else if (txtValue2 == 1) {
first();
}
else if (txtValue2 == pageCount()) {
last();
}
else {
hideTable();
page = txtValue2;
pageNum2.value = page;
currentRow = pageSize * page;
maxRow = currentRow - pageSize;
if (currentRow > numberRowsInTable) currentRow = numberRowsInTable;
for (var i = maxRow; i < currentRow; i++) {
theTable.rows[i].style.display = '';
}
if (maxRow == 0) { preText(); firstText(); }
showPage();
nextLink();
lastLink();
preLink();
firstLink();
}
txtValue = txtValue2;
}
}
</script>
<script type="text/javascript" src="js/Pagging.js"></script>
</body>
<table id="t_student" border="1" cellpadding="2" cellspacing="0" style="text-align:center;width:500px">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
</tr>
</thead>
<c:forEach items="${list}" var="st">
<tr>
<td>${st.getId()}</td>
<td>${st.getName()}</td>
</tr>
</c:forEach>
</table>
<div class="gridItem" style="padding: 5px; width: 250px; float: left; text-align: left; height: 20px; font-size: 15px;" >
共有 <span id="spanTotalInfor"></span> 條記錄
當前第<span id="spanPageNum"></span>頁
共<span id="spanTotalPage"></span>頁
</div>
<div class="gridItem" style="margin-left:50px; padding: 5px; width: 400px; float: left; text-align: center; height: 20px; vertical-align: middle; font-size: 15px;">
<span id="spanFirst" >首頁</span>
<span id="spanPre">上一頁</span>
<span id="spanInput" style="margin: 0px; padding: 0px 0px 4px 0px; height:100%; ">
第<input id="Text1" type="text" class="TextBox" onkeyup="changepage()" style="height:20px; text-align: center;width:50px" />頁
</span>
<span id="spanNext">下一頁</span>
<span id="spanLast">尾頁</span>
</div>
<script type="text/javascript">
var theTable = document.getElementById("t_student");
var txtValue = document.getElementById("Text1").value;
function changepage() {
var txtValue2 = document.getElementById("Text1").value;
if (txtValue != txtValue2) {
if (txtValue2 > pageCount()) {
}
else if (txtValue2 <= 0) {
}
else if (txtValue2 == 1) {
first();
}
else if (txtValue2 == pageCount()) {
last();
}
else {
hideTable();
page = txtValue2;
pageNum2.value = page;
currentRow = pageSize * page;
maxRow = currentRow - pageSize;
if (currentRow > numberRowsInTable) currentRow = numberRowsInTable;
for (var i = maxRow; i < currentRow; i++) {
theTable.rows[i].style.display = '';
}
if (maxRow == 0) { preText(); firstText(); }
showPage();
nextLink();
lastLink();
preLink();
firstLink();
}
txtValue = txtValue2;
}
}
</script>
<script type="text/javascript" src="js/Pagging.js"></script>
</body>