在页面上利用 标签 输出年月
<!-- -->
<select name="year">
<!-- 循环输出年代 -->
<c:set var="curYear" value="<%= Calendar.getInstance().get(Calendar.YEAR) %>"></c:set>
<c:forEach begin="0" end="10" var="step">
<option value="${curYear - step}"
<c:if test="${ (curYear - step) == year}">selected="selected"</c:if>
>${curYear - step}</option>
</c:forEach>
<c:remove var="curYear"/>
</select>
年
<label>
<select name="month">
<c:forEach begin="1" end="12" var="step">
<option value="${step}"
<c:if test="${step == month}">selected="selected"</c:if>
>${step}</option>
</c:forEach>
</select>
月
</label>
本文介绍了一种使用 JSP 和 JSTL 标签库动态生成年份和月份选择下拉菜单的方法。通过循环遍历当前年份及过去十年的数据,并根据需要选中特定的年份和月份。
246

被折叠的 条评论
为什么被折叠?



