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

📄 calendar.htm

📁 在很多项目中
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>选择日期</TITLE>
<STYLE>TD {
	FONT-SIZE: 12px; FONT-FAMILY: Tahoma, Verdana, sans-serif
}
</STYLE>

<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript>
var RE_NUM = /^\-?\d+$/;
// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;
// if need input time
var TIME_COMP = true;

// months as they appear in the calendar's title
var ARR_MONTHS = ["一月", "二月", "三月", "四月", "五月", "六月",
		"七月", "八月", "九月", "十月", "十一月", "十二月"];
// week day titles as they appear on the calendar
var ARR_WEEKDAYS = ["日", "一", "二", "三", "四", "五", "六"];
// day week starts from (normally 0-Mo or 1-Su)
var NUM_WEEKSTART = 0;
// path to the directory where calendar images are stored. trailing slash req.
var STR_ICONPATH = '';

//var dt_current = (window.dialogArguments) ? new Date(new Number(RegExp.$1)) : new Date());
//this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
var dt_current = new Date();
if (window.dialogArguments != null) {
  var arg = window.dialogArguments;
  dt_current = prs_tsmp(arg.str_datetime);
  if (dt_current == null) dt_current = new Date();
  TIME_COMP = arg.time_comp;
}

// get same date in the previous year
var dt_prev_year = new Date(dt_current);

// get same date in the next year
var dt_next_year = new Date(dt_current);

// get same date in the previous month
var dt_prev_month = new Date(dt_current);

// get same date in the next month
var dt_next_month = new Date(dt_current);

// get first day to display in the grid for current month
var dt_firstday = new Date(dt_current);

function init() {
  dt_prev_year = new Date(dt_current);
  dt_next_year = new Date(dt_current);
  dt_prev_month = new Date(dt_current);
  dt_next_month = new Date(dt_current);
  dt_firstday = new Date(dt_current);

  dt_prev_year.setFullYear(dt_prev_year.getFullYear() - 1);
  if (dt_prev_year.getDate() != dt_current.getDate())
    dt_prev_year.setDate(0);

  dt_next_year.setFullYear(dt_next_year.getFullYear() + 1);
  if (dt_next_year.getDate() != dt_current.getDate())
    dt_next_year.setDate(0);

  dt_prev_month.setMonth(dt_prev_month.getMonth() - 1);
  if (dt_prev_month.getDate() != dt_current.getDate())
    dt_prev_month.setDate(0);

  dt_next_month.setMonth(dt_next_month.getMonth() + 1);
  if (dt_next_month.getDate() != dt_current.getDate())
    dt_next_month.setDate(0);

  dt_firstday.setDate(1);
  dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);
}

init();

function print_yearmonth() {
  var strYearMonth = '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td>';
  strYearMonth += '<span style="color:#000080;background-color:#a0c6e5;cursor:hand" onclick="javascript:set_datetime(' + dt_prev_year.valueOf() + ')">';
  strYearMonth += '&lt;&lt;';
  strYearMonth += '</span>&nbsp;';
  strYearMonth += '<span style="color:#000080;background-color:#a0c6e5;cursor:hand" onclick="javascript:set_datetime(' + dt_prev_month.valueOf() + ')">';
  strYearMonth += '&lt;&nbsp;';
  strYearMonth += '</span>';
  strYearMonth += '</td>';
  strYearMonth += '<td align="center" width="100%"><font color="#ffffff">' + ARR_MONTHS[dt_current.getMonth()] + ' ' + dt_current.getFullYear() + '</font></td>';
  strYearMonth += '<td>';
  strYearMonth += '<span style="color:#000080;background-color:#a0c6e5;cursor:hand" onclick="javascript:set_datetime(' + dt_next_month.valueOf() + ')">';
  strYearMonth += '&nbsp;&gt;';
  strYearMonth += '</span>&nbsp;';
  strYearMonth += '<span style="color:#000080;background-color:#a0c6e5;cursor:hand" onclick="javascript:set_datetime(' + dt_next_year.valueOf() + ')">';
  strYearMonth += '&gt;&gt;';
  strYearMonth += '</span>';
  strYearMonth += '</td></tr></table>';
  yearmonth.innerHTML = strYearMonth;
}

function print_calendar() {
  var strCalendar = '<table cellspacing="1" cellpadding="3" border="0" width="100%">';

  // print weekdays titles
  for (var n=0; n<7; n++)
    strCalendar += ('<td bgcolor="#87cefa" align="center"><font color="#ffffff">' + ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7] + '</font></td>');

  var dt_current_day = new Date(dt_firstday);
  while (dt_current_day.getMonth() == dt_current.getMonth() ||
    dt_current_day.getMonth() == dt_firstday.getMonth()) {
    // print row heder
    strCalendar += ('<tr>');
    for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
      if (dt_current_day.getDate() == dt_current.getDate() &&
        dt_current_day.getMonth() == dt_current.getMonth())
        // print current date
        strCalendar += ('<td bgcolor="#ffb6c1" align="center" width="14%">');
      else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
        // weekend days
        strCalendar += ('<td bgcolor="#dbeaf5" align="center" width="14%">');
      else
        // print working days of current month
        strCalendar += ('<td bgcolor="#ffffff" align="center" width="14%">');

      strCalendar += ('<span  style="cursor:hand" onclick="javascript:set_datetime(' + dt_current_day.valueOf() + ', true);">');

      if (dt_current_day.getMonth() == this.dt_current.getMonth())
        // print days of current month
        strCalendar += ('<font color="#000000">');
      else
        // print days of other months
        strCalendar += ('<font color="#606060">');

      strCalendar += (dt_current_day.getDate()+'</font></a></td>');
      dt_current_day.setDate(dt_current_day.getDate()+1);
    }
    // print row footer
    strCalendar += ('</tr>');
  }
  strCalendar += ('</table>');
  calendar.innerHTML = strCalendar;
}

// timestamp generating function
function gen_tsmp (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function gen_date (dt_datetime) {
	return (
		dt_datetime.getFullYear() + "-"
    + (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
    + (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
	);
}
// time generating function
function gen_time (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function prs_tsmp (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);

	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function prs_date (str_date) {

	var arr_date = str_date.split('-');

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);

	if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[0]);

	var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
	dt_date.setDate(arr_date[2]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function prs_time (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0]))
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[1]) dt_date.setMinutes(0);

⌨️ 快捷键说明

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