我想對包含另一個表的表進行分頁, 我在我的JSP頁面中嘗試使用這個腳本函數,但是它工作到不包含另一個表的 這是函數:表的分頁包含表
<script type="text/javascript">
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;
this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
return;
}
var oldPageAnchor = document.getElementById('pg'+this.currentPage);
oldPageAnchor.className = 'pg-normal';
this.currentPage = pageNumber;
var newPageAnchor = document.getElementById('pg'+this.currentPage);
newPageAnchor.className = 'pg-selected';
var from = (pageNumber - 1) * itemsPerPage + 1;
var to = from + itemsPerPage - 1;
this.showRecords(from, to);
}
this.prev = function() {
if (this.currentPage > 1)
this.showPage(this.currentPage - 1);
}
this.next = function() {
if (this.currentPage < this.pages) {
this.showPage(this.currentPage + 1);
}
}
this.init = function() {
var rows = document.getElementById(tableName).rows;
var records = (rows.length - 1);
this.pages = Math.ceil(records/itemsPerPage);
this.inited = true;
}
this.showPageNav = function(pagerName, positionId) {
if (! this.inited) {
alert("not inited");
return;
}
var element = document.getElementById(positionId);
var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> « Prev </span> | ';
for (var page = 1; page <= this.pages; page++)
pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next »</span>';
element.innerHTML = pagerHtml;
}
}
</script>
<div id="pageNavPosition"></div>
<script type="text/javascript"><!--
var pager = new Pager('re', 2);
pager.init();
pager.showPageNav('pager', 'pageNavPosition');
pager.showPage(1);
//--></script>
並且這是表的代碼:
<table cellpadding="6" width="100%">
<thead >
<tr bgcolor="#FC6C85">
<th align="center"><img src="Logo.png" width="600" height="70" alt="Logo"/>
</th>
</thead>
</table>
<h1>Message Details</h1>
<table cellspacing='2'><tr><th align='center'> <form action="Controlleur?action=msgSum">
<a href="Controlleur?action=msgSum">Messages Summary</a></form></th><th align='center'> <form form action="Controlleur?action=sendmsg">
<input type="hidden" name="action" value="sendmsg" />
<a href="Controlleur?action=sendmsg">Send Messages</a></th></tr></table>
</form>
<table cellspacing="1" width=60% >
<tbody> <%for (int i = 0; i < msgController.getAllMessages().size(); i++) {%>
<% if ((Integer) (msgController.getAllMessages().get(i).getId_Author()) == (Integer.parseInt((String) session.getAttribute("usrid")))) {%>
<tr bgcolor="#FC6C85">
<% String autname=msgController.getAuthorName(msgController.getAllMessages().get(i).getId_Author());%>
<td width=20% ><form action="Controlleur?action=author"> <input type="hidden" name="action" value="author" />
<input type="hidden" name="author" value=""/>
<a href="Controlleur?action=author&author=<%=autname%>"><%=autname%></a>
</form>
</td>
<td><table><tr><td width=20%><%=msgController.getAllMessages().get(i).getTitle()%></td>
<td width=20%><form action="Controlleur?action=editMessage">
<input type="hidden" name="action" value="editMessage" />
<input type="hidden" name="titrem" value="<%=msgController.getAllMessages().get(i).getTitle()%>" />
<input type="hidden" name="subjm" value="<%=msgController.getAllMessages().get(i).getSubject()%>" />
<input type="hidden" name="mgid" value="<%=msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())%>" />
<input type="submit" value="Edit" name="editMessage" /></form></td>
<td width=20%><form action="Controlleur?action=deleteMessage">
<input type="hidden" name="action" value="deleteMessage" />
<input type="hidden" name="mgidd" value="<%=msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())%>" />
<input type="submit" value="Delete" name="deleteMessage" /></form></td>
</tr></table></tr>
<tr><td></td><td colspan="3" width=30% height=10><%=msgController.getAllMessages().get(i).getSubject()%></td></tr>
<tr><td></td><td colspan="3" width=30%><font color="#CB2C71"><%=msgController.getAllMessages().get(i).getDates()%></font></td></tr>
<tr> <td></td><td><table id='re' ><thead><tr><th colspan="3">Comments</th>
<th>Date</th></tr></thead><%for (int h = 0; h < cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).size(); h++) {%>
<tr><td bgcolor="#FC6C85"><form action="Controlleur?action=author">
<input type="hidden" name="action" value="author" />
<%String authorName = cmt.getAuthorName(cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getId_pers());
int commentId=cmt.getId(cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getDate());
int idPers=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getId_pers();
int idAuthor=Integer.parseInt((String)session.getAttribute("usrid"));
%>
<input type="submit" value="<%=authorName%>" name="author" />
</form></td><td><%=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getSubject()%>
</td><td></td><td><%=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getDates()%></td><td>
</td><%if(idPers==idAuthor){%>
<td><form action="Controlleur?action=deleteComment">
<input type="hidden" name="action" value="deleteComment"/>
<input type="hidden" name="cmtID" value="<%=commentId%>"/>
<a href="Controlleur?action=deleteComment&cmtID=<%=commentId%>">delete</a>
</form></td>
<td><form action="Controlleur?action=updateComment">
<input type="hidden" name="action" value="updateComment"/>
<input type="hidden" name="cmtID" value="<%=commentId%>"/>
<a href="Controlleur?action=updateComment&cmtID=<%=commentId%>">Edit</a></form></td>
<%}%>
</tr>
<tr bgcolor="#FC6C85"></tr><%}%>
<tr><form action="Controlleur?action=addcomment"><td></td><td colspan="2">
<textarea name="commentSubject" value="" rows="1" cols="38" ></textArea></td>
「/>
<%}否則{%> <%字符串autname = msgController.getAuthorName(msgController.getAllMessages()得到(ⅰ).getId_Author()。);%> 「> <% = autname%> <%= msgController.getAllMessages()。得到(ⅰ).getTitle()%> <%= msgController.getAllMessages()。得到(ⅰ).getSubject()%> <%= msgController.getAllMessages()獲得(I).G etDates()%>
評論 日期< for(int h = 0; ().getId_Author(),msgController.getAllMessages()。get(i).getTitle(),msgController.getAllMessages()。get(i).getAllComments(msgController.getMessageID(msgController.getAllMessages .getSubject(),msgController.getAllMessages()。get(i).getDate()))。size();^h ++){%>
<tr><td bgcolor="#FC6C85"><form action="Controlleur?action=author">
<input type="hidden" name="action" value="author" />
<%String authorName = cmt.getAuthorName(cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getId_pers());
int commentId=cmt.getId(cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getDate());
int idPers=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getId_pers();
int idAuthor=Integer.parseInt((String)session.getAttribute("usrid"));
%>
<input type="submit" value="<%=authorName%>" name="author" />
</form></td><td><%=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getSubject()%>
</td><td></td><td><%=cmt.getAllComments(msgController.getMessageID(msgController.getAllMessages().get(i).getId_Author(), msgController.getAllMessages().get(i).getTitle(), msgController.getAllMessages().get(i).getSubject(), msgController.getAllMessages().get(i).getDate())).get(h).getDates()%></td><td>
</td><%if(idPers==idAuthor){%>
<td><form action="Controlleur?action=deleteComment">
<input type="hidden" name="action" value="deleteComment"/>
<input type="hidden" name="cmtID" value="<%=commentId%>"/>
<a href="Controlleur?action=deleteComment&cmtID=<%=commentId%>">delete</a>
</form></td>
<td><form action="Controlleur?action=updateComment">
<input type="hidden" name="action" value="updateComment"/>
<input type="hidden" name="cmtID" value="<%=commentId%>"/>
<a href="Controlleur?action=updateComment&cmtID=<%=commentId%>">Edit</a></form></td>
<%}%>
</tr>
<tr bgcolor="#FC6C85"></tr><%}%>
<tr><form action="Controlleur?action=addcomment"><td></td><td colspan="2">
<textarea name="commentSubject" value="" rows="1" cols="38" ></textArea></td>
「/>
<%} }%>
你能幫助我請
請張貼表格本身的代碼。 – TiiJ7