if(skins != null){<br /> Iterator it = skins.keySet().iterator();<br /> // 關鍵代碼<br /> int i=0;<br /> while(it.hasNext()){<br /> String key = (String) it.next();<br /> SkinEntry skin = (SkinEntry)skins.get(key);<br /> String skinName = skin.getName();<br /> String skinTitle = skin.getTitle();<br /> String imageNormal = skin.getImage_normal();<br /> String author = skin.getAuthor();<br /> String deplytime = skin.getDeploytime();<br /> // 關鍵代碼<br /> if(i%3==0) out.println("<tr>") ;<br /> String onclick = "onclick=/"doSelectSkin('"+skinName+"')/"";<br /> String onmousemove = "onmousemove=/"className='select_on_style'/"";<br /> String onmouseout = "onmouseout=/"className=''/"";<br /> String sClass = "";<br /> String sImag = "";<br /> if(skinName.equals(sCurrent_skin)){<br /> sClass = "class=/"select_on_style/"";<br /> onmousemove = "";<br /> onmouseout = "";<br /> onclick = "";<br /> sImag = "<img src="/" mce_src="/""/images/skin_select.gif/">";<br /> }<br /> %><br /> <td><br /> <table height="180px" <%=sClass%> cellpadding="" cellspacing="3" <%=onclick%> width="220px" <%=onmousemove%> <%=onmouseout%>><br /> <tr><br /> <td align="center"><img src="<%=imageNormal%>"/><%=sImag%></td><br /> </tr><br /> <tr><br /> <td align="center"><%=skinTitle%></td><br /> </tr><br /> <tr><br /> <td align="center">作者:<%=author%></td><br /> </tr><br /> <tr><br /> <td align="center">發布時間:<%=deplytime%></td><br /> </tr><br /> </table><br /> </td><br /> // 關鍵代碼<br /> <%<br /> if((i+1)%3==0) out.println("</tr>") ;<br /> i++;<br /> }<br /> if(skins.size()%3!=0) {<br /> out.println("<td colspan='" + (3 - skins.size()%3) + "'> </td></tr>") ;<br /> }<br /> }%>
以上代碼為,每輸出三個td還一行,最後不夠用空的td代替。例如:輸出5個內容,第二行就不夠了,為了是代碼完整,在這裡就以<td>&nbps;</td>來進行填充。這個地方經常會在頁面顯示圖片預覽是用到。