jsp頁面年份下拉框生成當前年的前n年和後n年
阿新 • • 發佈:2019-02-14
因為要用到Calendar方法,首先要匯入Calendar類所在的包。
<%@ page import="java.util.Calendar"%>
- <select name='year'>
- <option></option>
- <% Calendar cal = Calendar.getInstance();
- int year = cal.get(Calendar.YEAR)-10;
- for(int i=1; i<=21; i++){
- String str = String.valueOf(year);
- if(str.equals(request.getParameter
- %>
- <option selected="selected"><%=str%></option>
- <%} else{%>
- <option><%=str%></option>
- <%} year = year + 1;
- }%>
- </select>
當頁面重新整理後,使用if語句判斷以前被選中的年份顯示在頁面
然後就可以在前端檢視效果,並根據需要進行調整
轉自https://blog.csdn.net/u012739535/article/details/24342695