<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.Calendar" %>
<html>
<head>
<title>日历</title>
<style>
table{
border: none;
}
table caption{
color: red;
}
table tr th{
text-align: center;
border: 1px solid yellow;
background-color: yellow;
}
table tr td{
text-align: center;
border: 1px solid gainsboro;
}
table tr td:hover{
border: 1px solid red;
cursor: pointer;
}
</style>
</head>
<body>
<table cellspacing="3" align="center">
<%
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH)+1;
%>
<caption><strong>日历</strong></caption>
<caption><strong><%=year%>年<%=month%>月</strong></caption>
<tr>
<th><div style="color:red">日</div></th>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th><div style="color:green">六</div></th>
</tr>
<%
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH,1);
int day=1;
int firstDay = ca.get(Calendar.DAY_OF_WEEK);
int totalDays = ca.getActualMaximum(Calendar.DATE);
int today = now.get(Calendar.DATE);
for (int i=1;i<=6;i++){
%>
<tr>
<%
for (int j=1;j<=7;j++){
if(j<firstDay&&i==1||day>totalDays){
%>
<td bgcolor="#dcdcdc"><div style="color:gainsboro">-</div></td>
<%
}else{
if (day==today){
%>
<td bgcolor="red"><%=day%></td>
<%
day++;
}else{
%>
<td bgcolor="#dcdcdc"><%=day%></td>
<%
day++;
}
}
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
jsp实现日历(二)
最新推荐文章于 2021-03-22 11:17:25 发布