⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar.jsp

📁 负责公文的传输及一些处理功能
💻 JSP
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page contentType="text/html; charset=GBK" import="com.example.util.DateWrapper, java.util.*" %>
<%
/**********************************************************************
 使用日历组件,由孟志勇整理汉化,并增加新功能。
 版权所有,盗版必究。
 源程序由SiteExpert提供。

传入参数:日历的起始和结束的年份,例如要显示1995~2000年,yearBegin=1995, yearEnd=2001,缺省显示当前前后5年的日历
当前日期:defaultDate,缺省显示当前时间
客户端调用方法:
<SCRIPT language="javascript">

 function DoCal(elTarget) {
  if (!window.showModalDialog)	return;
  var sRtn;
  //指定起始、结束年份以及缺省日期
  sRtn = showModalDialog("calendar.jsp?defaultDate=1998-7-24","","help=no;status=no;center=yes;dialogWidth=350pt;dialogHeight=200pt");

  if (sRtn!="")
	elTarget.value = sRtn;
 }
</SCRIPT>
***********************************************************************/


String strYearBegin = request.getParameter("beginYear");
String strYearEnd = request.getParameter("endYear");
String strDefaultDate = request.getParameter("defaultDate");
Calendar cal = new GregorianCalendar();
try {
  Date defaultDate = DateWrapper.getDate(strDefaultDate);
  cal.setTime(defaultDate);
} catch(Exception e) {

}
int year = cal.get(cal.YEAR);
int month = cal.get(cal.MONTH);
int day = cal.get(cal.DATE);

int yearBegin = year - 15;
int yearEnd = year + 5;
try{
  yearBegin = Integer.parseInt(strYearBegin);
  yearEnd = Integer.parseInt(strYearEnd);
}catch (Exception e){

}
%>

<HTML><HEAD>
   <TITLE>日历</TITLE>

   <link rel="stylesheet" href="../csslib/style.css">

   <STYLE TYPE="text/css">
      .today {color:#990000; font-weight:bold}
      .days {font-family:"宋体"; background-color:#F4FD01"}
   </STYLE>
   <SCRIPT LANGUAGE="JavaScript">
      // Initialize arrays.
      var months = new Array("一月", "二月", "三月","四月", "五月", "六月", "七月", "八月", "九月","十月", "十一月", "十二月");
      var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
      var days = new Array("日", "一", "二","三", "四", "五", "六");

      function getDays(month, year)
      {
         // Test for leap year when February is selected.
         if (1 == month)  return (((0 == year % 4) && (0 != (year % 100)))||0 == year % 400) ? 29 : 28;
         else			  return daysInMonth[month];
      }

      function getToday()
      {
         // Generate today's date.
         this.year = <%=year%>;
         this.month = <%=month%>;
         this.day = <%=day%>;
      }

      // Start with a calendar for today.
      today = new getToday();

      function newCalendar()
      {
         today = new getToday();
         var parseYear = parseInt(document.all.year[document.all.year.selectedIndex].text);
         var newCal = new Date(parseYear,document.all.month.selectedIndex,1);
         var day = -1;
         var startDay = newCal.getDay();
         var daily = 0;

         if ((today.year == newCal.getFullYear()) && (today.month == newCal.getMonth())) day = today.day;
         // Cache the calendar table's tBody section, dayList.
         var tableCal = document.all.calendar.tBodies.dayList;
         var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
         for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++)
            for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length; intDay++)
            {
               var cell = tableCal.rows[intWeek].cells[intDay];

               // Start counting days.
               if ((intDay == startDay) && (0 == daily)) daily = 1;

               // Output the day number into the cell.
               if ((daily > 0) && (daily <= intDaysInMonth))
               {
 				// Highlight the current day.
 				cell.className = (day == daily) ? "today" : "";
 				cell.innerText = daily++;
 			  }
              else  cell.innerText = "";
            }
      }

      function getDate()
      {
 	 	var sDate;
         // This code executes when the user clicks on a day
         // in the calendar.
         if ("TD" == event.srcElement.tagName)
            // Test whether day is valid.
            if ("" != event.srcElement.innerText)
            {
               //alert(event.srcElement.innerText);
 			  sDate = document.all.year.value + "-" + document.all.month.value + "-" + event.srcElement.innerText;
 			  document.all.ret.value = sDate;
 	  		  window.close();
 	  		}
      }

      function ChangeColor()
      {
 		if ("TD" == event.srcElement.tagName)
 		{
 			if ("" != event.srcElement.innerText)
 			{
 				event.srcElement.style.backgroundColor = '#CAC81A';
 				event.srcElement.style.cursor = "hand";
 			}
 		}
      }

      function RestoreColor()
      {
 		if ("TD" == event.srcElement.tagName)
 		{
 			if ("" != event.srcElement.innerText)
 			{
 				event.srcElement.style.backgroundColor = "";
 				event.srcElement.style.cursor = "";
 			}
 		}
      }
   </SCRIPT>
</HEAD>
<BODY ONLOAD="newCalendar()" OnUnload="window.returnValue = document.all.ret.value;" scroll="no">
	 <Fieldset class="THeader">
        <Table  align="center" width="264px" >
        <TR align="center">
			 <TD align=left>
 		     <!-- Year combo box -->
              <SELECT ID="year" ONCHANGE="newCalendar()">
                 <SCRIPT LANGUAGE="JavaScript">
                    // Output years into the document.
                    // Select current year.
                    for (var intLoop = <%=yearBegin%>; intLoop < (<%=yearEnd%>);intLoop++)
                       document.write("<OPTION VALUE= " + intLoop + " " +(today.year == intLoop ?"Selected" : "") + ">" +intLoop);
                 </SCRIPT>
              </SELECT>
              </TD>
              <!--td><a href="#" onclick="javascript:location.reload()">当前时间</a></td-->
              <TD align=right>
              <!-- Month combo box -->
              <SELECT ID="month" ONCHANGE="newCalendar()">
                 <SCRIPT LANGUAGE="JavaScript">
                    // Output months into the document.
                    // Select current month.
                    for (var intLoop = 0; intLoop < months.length;intLoop++)
                       document.write("<OPTION VALUE= " + (intLoop + 1) + " " +(today.month == intLoop ?"Selected" : "") + ">" +months[intLoop]);
                 </SCRIPT>
              </SELECT>&nbsp;&nbsp;&nbsp;
          </TD>
          </tr>
          </Table>
      </Fieldset>

      <fieldset>
		<TABLE border="1" bordercolor="#006230" align="center" >
		<TR >
			<!-- Generate column for each day. -->
			<SCRIPT LANGUAGE="JavaScript">
			   // Output days.
			   for (var intLoop = 0; intLoop < days.length;intLoop++)
			      document.write("<TD width=28px style='color:#000000' align='center'>" + days[intLoop] + "</TD>");
			</SCRIPT>
		</TR>
		</Table>

		<TABLE ID="calendar" class="Td1" border="1" bordercolor="#000000" cellpadding="0" height="130px" align="center" >
		<TBODY ID="dayList"ALIGN=CENTER ONCLICK="getDate()" onmousemove="ChangeColor()" onmouseout="RestoreColor()">
		    <!-- Generate grid for individual days. -->
		    <SCRIPT LANGUAGE="JavaScript">
		       for (var intWeeks = 0; intWeeks < 6; intWeeks++)
		       {
		          document.write("<TR>");
		          for (var intDays = 0; intDays < days.length;intDays++) document.write("<TD width=30px></TD>");
		          document.write("</TR>");
		       }
		    </SCRIPT>
		 </TBODY>
		 </TABLE>
     </fieldset>
    <input type="hidden" name="ret">
</BODY>
</HTML>

<Script Language="JavaScript1.2">

</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -