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

📄 calendar.js

📁 一个完整的办公资源管理系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
// callCalendar(): Examines the objectId's value to see if a seed year, month, and/or day
//                 are present to use for seeding generateCalendar(), and then calls
//                 generateCalendar() with the objectId as the target.
//
function callCalendar( objectId ){

	var dateString=document.getElementById( objectId ).value;
	// Normalize possibly variant delimiters to the ISO preferred delimiter:
	var re = new RegExp( '[/\.\ ]', 'gi' );
	dateString=dateString.replace( re, "-" );
	// Split the date string:
	dateComponents=dateString.split("-");
	var year,month,day;
	year=dateComponents[0];
	month=dateComponents[1];
	day=dateComponents[2];
	generateCalendar( year, month, day, objectId );

}

//
// setDate()
//
function setDate(day){

	// Format the date string:
	year =document.getElementById("currentYear").value;
	month=document.getElementById("currentMonth").value;
	isoDateString=formatISODate(year,month,day);
	// Get the destination object id:
//	idString = document.getElementById("destinationId").value;
//	alert(isoDateString);
	// Store the value:
	calendarlist.location.href="dailywork_list.htm";//document.getElementById( idString ).value=isoDateString;
//	window.close();
//
}

//
// previousYear()
//
function previousYear(){

	year =parseInt(document.getElementById("currentYear").value);
	month=parseInt(document.getElementById("currentMonth").value);
	day  =parseInt(document.getElementById("currentDay").value);
	destination = document.getElementById("destinationId").value;
	year -= 1;
	// Remember that there was no year zero:
	if( year==0 ) year = -1;
	//
	// NOTE BENE: The generateCalendar() function *MUST* be called
	// from the "window.opener" window.  Otherwise, if you just call
	// "generateCalendar()" from *this* window, then the "opener"
	// property becomes the calendar popup window itself in the new
	// incarnation of the calendar window -- instead of being
	// the form window -- and then you would be stuck with no
	// way to access the form elements in the main form window!
	//
//	window.opener.generateCalendar(year,month,day,destination);
	generateCalendar(year,month,day,destination);
}

//
// previousMonth()
//
function previousMonth(){

	year =parseInt(document.getElementById("currentYear").value);
	month=parseInt(document.getElementById("currentMonth").value);
	day  =parseInt(document.getElementById("currentDay").value);
	destination = document.getElementById("destinationId").value;
	month -= 1;
	if(month<1){
		month = 12;
		year -= 1;
		if( year==0 ) year = -1;
	}
//	window.opener.generateCalendar(year,month,day,destination);
	generateCalendar(year,month,day,destination);
}

//
// nextMonth()
//
function nextMonth(){

	year =parseInt(document.getElementById("currentYear").value);
	month=parseInt(document.getElementById("currentMonth").value);
	day  =parseInt(document.getElementById("currentDay").value);
	destination = document.getElementById("destinationId").value;
	month += 1;
	if(month>12){
		month = 1;
		year += 1;
		if( year==0 ) year = 1;
	}
//	window.opener.generateCalendar(year,month,day,destination);
	generateCalendar(year,month,day,destination);

}

//
// nextYear()
//
function nextYear(){

	year =parseInt(document.getElementById("currentYear").value);
	month=parseInt(document.getElementById("currentMonth").value);
	day  =parseInt(document.getElementById("currentDay").value);
	destination = document.getElementById("destinationId").value;
	year += 1;
	// Remember that there was no year zero:
	if( year==0 ) year = 1;
//	window.opener.generateCalendar(year,month,day,destination);
	generateCalendar(year,month,day,destination);
}

//
// generateCalendar()
//
// Arguments: Year, Month, Day, and the ID of the target element.
//
// This function creates the popup calendar.  Clicking on a date
// populates the target element with the chosen date in ISO 8601
// YYYY-MM-DD format (for Common Era years: years before Common Era
// are prefixed with a negative sign) and closes the popup window.
//
function generateCalendar( Y, M, D, targetId ){

	// Names of the Months:
	//var Month = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	//var Month = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
	var Month = new Array("1","2","3","4","5","6","7","8","9","10","11","12");
	// Days of the Week:
	//var Day = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	//var Day = new Array("日","一","二","三","四","五","六");
	var Day = new Array("<img src='../images/7.gif'>","<img src='../images/1.gif'>","<img src='../images/2.gif'>","<img src='../images/3.gif'>","<img src='../images/4.gif'>","<img src='../images/5.gif'>","<img src='../images/6.gif'>");
	// Digits (if you want to use something other than Arabic-Indic digits):
	// var Digits = new Array("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");

	var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var daysInAWeek=7;
	var OutputString;

	// Guard against arguments that are really passed as strings:
	// Get year:
	var today = new Date();
	if( Y=="" || isNaN(Y) ){
		thisYear=today.getFullYear();
	}else{
		thisYear=parseInt(Y);
	}
	// Get month:
	if( M=="" || isNaN(M) ){
		thisMonth=today.getMonth()+1;
	}else{
		thisMonth=parseInt(M);
		if(thisMonth<1) thisMonth=1;
		if(thisMonth>12) thisMonth=12;
	}
	// Get day:
	if( D=="" || isNaN(D) ){
		thisDay=today.getDate();
	}else{
		thisDay=parseInt(D);
		if(thisDay<0) thisDay=1;
		if(thisDay>31) thisDay=31;
	}

	// Calculate the number of days in February:
	if ((thisYear % 4) == 0){
		daysInMonth[ 1 ] = 29;
		if((thisYear % 100) == 0 && (thisYear % 400) != 0){
			daysInMonth[ 1 ] = 28;
		}
	}

	// Document header:
	OutputString = "<%@ page contentType=\"text/html; charset=GBK\" %>";
	OutputString += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0.1//EN\"\n";
	OutputString += "   \"http://www.w3.org/TR/html4/strict.dtd\">\n";
	OutputString += "<html>\n <head>\n";
	OutputString += "  <title>Gladiator \uFFFD\uFFFDュ\uFFFD\uFFFD</title>\n";
	OutputString += "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=2312\">\n";
	OutputString += "  <link href=\"../style/styles.css\" rel=\"STYLESHEET\" type=\"text/css\">\n <link rel=\"stylesheet\" title=\"Default Style\" href=\"../style/calendar.css\" type=\"text/css\" media=\"screen\">\n";
	OutputString += "  <script type=\"text/javascript\" src=\"../style/calendar.js\"></script>\n";
	OutputString += " </head>\n <body class=\"body0\" id=\"mycal\">\n";

	// Start the calendar table with day headings:
	OutputString += "<table border='1' align='center'>\n <tr>\n";
	OutputString += "<td class='calendarheading' colspan='7' align='center'><table class='normal' width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td class='normal' width='21'>&nbsp;</td>\n";
//	OutputString += " <td class=\"calendarheading\"><div class=\"cssleftstretcharrow\" onclick=\"previousYear()\"><!-- left arrow --></div></td>\n";
//	OutputString += " <td class=\"calendarheading\"><div class=\"cssleftarrow\" onclick=\"previousMonth()\"><!-- left arrow --></div></td>\n";
	OutputString += " <td class=\"normal\"><img style='cursor:hand' src='../images/preyear.gif' onclick=\"previousYear()\"></td>\n";
	OutputString += " <td class=\"normal\"><img style='cursor:hand' src='../images/premonth.gif' onclick=\"previousMonth()\"></td>\n";
	// Print the year heading: If year<0, negate and print "BCE"; if 0<year<1000, print "CE":
//	OutputString += " <td class=\"calendarheading\" colspan=\"3\">";
	if( thisYear < 0 ) yearString = -thisYear + " BCE";
	else if( thisYear < 1000 ) yearString = thisYear + " CE";
	else yearString = thisYear;
	OutputString += "<td class='normal' width='30'>"+yearString + "</td><td class='normal'><img src='../images/year.gif'></td>";
	// Print the month heading:
	OutputString += "<td class='normal' width='20'>"+Month[ thisMonth-1 ] + "</td><td class='normal'><img src='../images/month.gif'></td>";

//	OutputString += " <td class=\"calendarheading\"><div class=\"cssrightarrow\" onclick=\"nextMonth()\"><!-- right arrow --></div></td>\n";
//	OutputString += " <td class=\"calendarheading\"><div class=\"cssrightstretcharrow\" onclick=\"nextYear()\"><!-- right arrow --></div></td>\n";
	OutputString += " <td class=\"normal\"><img style='cursor:hand' src='../images/nextmonth.gif' onclick=\"nextMonth()\"></td>\n";
	OutputString += " <td class=\"normal\"><img style='cursor:hand' src='../images/nextyear.gif' onclick=\"nextYear()\"></td>\n";
	OutputString += "<td class='normal' width='21'>&nbsp;</td></tr></table></td></tr>\n <tr>\n";
	for(i=0;i<daysInAWeek;i++){
		OutputString += "  <th>" + Day[i] + "</th>\n";
	}
	OutputString += " </tr>\n <tr>\n";

	// Get the day of week of the first of the month:
	var firstDay=dayOfWeek( julianDay( thisYear, thisMonth, 1 ) );
	//alert( Day[ firstDay ] );

	// First week:
	for(i=0;i<firstDay;i++){
		OutputString += "  <td>&nbsp;</td>\n";
	}
	for(d=1;i<daysInAWeek;i++,d++){
		// Special handling for October of 1582:
		if( d==5 && thisMonth==10 && thisYear==1582 ) d+=10;
		OutputString += "  <td";
		if(d==thisDay) OutputString += " onmouseover=\"this.className='thisdayhover'\" onmouseout=\"this.className='thisday'\" class='thisday'";
		else OutputString += " onmouseover=\"this.className='tdhover'\" onmouseout=\"this.className='tdnormal'\"";
		OutputString += " onclick=\"setDate(" + d + ")\">" + d + "</td>\n";
	}

	// Subsequent weeks;
	var lastDayOfMonth=daysInMonth[thisMonth-1];
	for(j=1;j<6 && d<=lastDayOfMonth;j++){
		OutputString += " </tr>\n <!-- Week " + (j+1) + " -->\n<tr>\n";
		// Days in this month:
		for( i=0; i<daysInAWeek && d<=lastDayOfMonth;i++,d++){
			OutputString += "  <td";
			if(d==thisDay) OutputString += " onmouseover=\"this.className='thisdayhover'\" onmouseout=\"this.className='thisday'\" class='thisday'";
			else OutputString += " onmouseover=\"this.className='tdhover'\" onmouseout=\"this.className='tdnormal'\"";
			OutputString += " onclick=\"setDate(" + d + ")\">" + d + "</td>\n";
		}
		// Finish out the row:
		for(;i<daysInAWeek;i++){
			OutputString += "  <td>&nbsp;</td>\n";
		}
	}
	// Finish the HTML, with hidden vars:
	OutputString += "  </tr>\n";
	OutputString += " </table>\n";
	OutputString += " <p>\n";
	OutputString += "  <input type=\"hidden\" id=\"currentYear\" value=\"" + thisYear + "\">\n";
	OutputString += "  <input type=\"hidden\" id=\"currentMonth\" value=\"" + thisMonth + "\">\n";
	OutputString += "  <input type=\"hidden\" id=\"currentDay\" value=\"" + thisDay + "\">\n";
	OutputString += "  <input type=\"hidden\" id=\"destinationId\" value=\"" + targetId + "\">\n";
//	OutputString += " </p>\n ";
	OutputString += " </p>\n </body>\n</html>\n";

//	var calendarWindow;
//	if( !calendarWindow || calendarWindow.closed() ){
//		calendarWindow = window.open("","Calendar","screenX=50, screenY=50, width=325, height=275,resizable=no");
//	}
//	document.clear();
	document.write(OutputString);
	document.close();

}

⌨️ 快捷键说明

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