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

📄 datetime.js

📁 这是我上次报java培训时
💻 JS
📖 第 1 页 / 共 4 页
字号:
      theLeftDay = 31;
    }else{
      theLeftDay = this.GetMonthDays(theYear, theMonth - 1);
    }
    var theRightDay = this.GetMonthDays(theYear, theMonth);
    var theCurrentDay = theLeftDay - theWeek + 1;
    var offsetMonth = -1; //the month is previous month
    var theColor = this.InvalidColor;
    var theBgColor = this.UnselectBgColor;
    var theBdColor = theBgColor;
    var WeekId = 0
    var DayId = 0;
    var theStyle = "";
    var theDayHTML = "<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    theDayHTML += "		<tr style=\"" + this.TitleStyle + "\">";
    for (DayId = 0; DayId < 7; DayId++){
      theDayHTML += "		<td width=\"10%\">" + this.WeekName[DayId] + "</td>";
    }
    theDayHTML += "		</tr>";
    theDayHTML += "		<tr>";
	theDayHTML += "			<td colspan=\"7\" style=\"" + this.LineBgStyle + "\">";
    theDayHTML += "				<table style=\"" + this.LineStyle + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    theDayHTML += "					<tr><td></td></tr>";
	theDayHTML += "				</table>";
    theDayHTML += "			</td>";
	theDayHTML += "		</tr>";
    for (WeekId = 0; WeekId < 6; WeekId++){
      theDayHTML += "	<tr style=\"" + this.DayStyle + "\">";
      for (DayId = 0; DayId < 7; DayId++){
	    if ((theCurrentDay > theLeftDay) && (WeekId < 3)){
	      offsetMonth++; //the month is current month;
	      theCurrentDay = 1;
	    }
	    if ((theCurrentDay > theRightDay) && (WeekId > 3)){
	      offsetMonth++; //the month is next month;
	      theCurrentDay = 1;
	    }
	    switch (offsetMonth){
	      case -1:
		    theColor = this.InvalidColor;
		    break;
		case 1:
		    theColor = this.InvalidColor;
		    break;
		case 0:
		    if ((DayId==0)||(DayId==6)){
		      theColor = this.WeekendColor;
		    }else{
		      theColor = this.ValidColor;
		    }
		    break;
	    }
	    if ((DayId==0)||(DayId==6)){
	      theBgColor = this.WeekendBgColor;
	    }else{
	      theBgColor = this.UnselectBgColor;
	    }
	    theBdColor = this.DayBdColor;
	    if ((theCurrentDay == theDay) && (offsetMonth == 0)){
	      theColor = this.SelectedColor;
	      theBgColor = this.SelectedBgColor;
		  theBdColor = theBgColor;
	    }
	    if ((theYear == theCurrentDate.getFullYear()) && (theMonth == theCurrentDate.getMonth()) && (theCurrentDay == theCurrentDate.getDate()) && (offsetMonth == 0)){
		  theBdColor = this.TodayBdColor;
	    }
	    theStyle = "border:" + this.DayBdWidth + "px solid " + theBdColor + "; color:" + theColor + "; background-color:" + theBgColor + ";";
	    theDayHTML += "		<td style=\"" + theStyle + "\" onMouseOver=\"" + this.OverDayStyle + "\" onMouseOut=\"" + this.OutDayStyle + "\" onMouseDown=\"document.jsMonthView.CreateMonthGrid(" + theYear.toString() + ", " +
	    (theMonth + offsetMonth).toString() + ", " + theCurrentDay.toString() + ", " + this.formatTime(theCurrentDate.getHours()) + ", " + this.formatTime(theCurrentDate.getMinutes()) + ", " + this.formatTime(theCurrentDate.getSeconds()) +
	    ");"+theName+"_MonthView.style.visibility='hidden' \">";

	    theDayHTML += theCurrentDay.toString();
	    theDayHTML += "		</td>";
	    theCurrentDay++;
	  }
	  theDayHTML += "	</tr>";
    }
    theDayHTML += "		<tr style=\"" + this.FooterStyle + "\" onMouseDown=\"document.jsMonthView.CreateMonthGrid(" + theCurrentDate.getFullYear().toString() + ", " + theCurrentDate.getMonth().toString() + ", " + theCurrentDate.getDate().toString() + ", " + this.formatTime(theCurrentDate.getHours()) + ", " + this.formatTime(theCurrentDate.getMinutes()) + ", " + this.formatTime(theCurrentDate.getSeconds())+ ");\">";
    theStyle = "border:" + this.DayBdWidth + "px solid " + this.TodayBdColor + ";";
    theDayHTML += "			<td style=\"" + theStyle + "\">";
    theDayHTML += "			&nbsp;" + this.TodayTitle;
    theDayHTML += "			</td>";
	var tmpCurrentDate = this.SetDateFormat(theCurrentDate.getFullYear(), theCurrentDate.getMonth(), theCurrentDate.getDate(), theCurrentDate.getHours(), theCurrentDate.getMinutes(),theCurrentDate.getSeconds());
	if (this.hasTime)
		tmpCurrentDate = tmpCurrentDate.substr(0,tmpCurrentDate.length-8);
    theDayHTML += "			<td colspan=\"6\"> " + "&nbsp;&nbsp;" + tmpCurrentDate + "</td>";
    theDayHTML += "		</tr>";
    theDayHTML += "	</table>";
    var theMonthGrid = document.all.item(theName + "_MonthGrid");
    theMonthGrid.innerHTML = theDayHTML;
  }
  this.CreateMonthGrid = function(theYear, theMonth, theDay,theHour,theMinute,theSecond){ //refresh the month view to the date, main action is run this.setDayList() and set this.Source.value
    var theTextObject = this.Source;
    if (theTextObject == null){
      return;
    }
    var theName = this.Name;
    var theYearObject = document.all.item(theName + "_YearList");
    var theMonthObject = document.all.item(theName + "_MonthList");
    var tmpYear = theYear;
    var tmpMonth = theMonth;
    var tmpDay = 1;
    if (tmpMonth < 0){
      tmpYear--;
	  tmpMonth = 11;
    }
    if (tmpMonth > 11){
      tmpYear++;
	  tmpMonth = 0;
    }
    if (tmpYear < this.MinYear){
      tmpYear = this.MinYear;
    }
    if (tmpYear > this.MaxYear){
      tmpYear = this.MaxYear;
    }
    if (theDay < 1){
	  tmpDay = 1;
	}else{
      tmpDay = this.GetMonthDays(tmpYear, tmpMonth);
      if (theDay < tmpDay){
	    tmpDay = theDay;
	  }
	}
    theYearObject.value = tmpYear;
    theMonthObject.value = tmpMonth;
	var tmpHour = theHour;
	var tmpMinute = theMinute;
	var tmpSecond = theSecond;
    this.setDayList(tmpYear, tmpMonth, tmpDay, tmpHour, tmpMinute, tmpSecond);
    theTextObject.value = this.SetDateFormat(tmpYear, tmpMonth, tmpDay, tmpHour, tmpMinute, tmpSecond);
    //theTextObject.select();
	if (!isNaN(this.fObj))
		this.fObj.focus();
  }
  this.CreateMonth = function(theYear, theMonth, theDay,theHour,theMinute,theSecond){ //refresh the month view to the date, main action is run this.setDayList() and set this.Source.value
    var theTextObject = this.Source;
    if (theTextObject == null){
      return;
    }
	this.CreateMonthGrid(theYear, theMonth, theDay,theHour,theMinute,theSecond);
    theTextObject.select();
  }
  this.UpdateMonthGrid = function(theObject,isNow){ //run this.CreateMonthGrid() by theObject
    var theTextObject = this.Source;
    if (theTextObject == null){
      return;
    }
	var theName = this.Name;
    var theYearObject = document.all.item(theName + "_YearList");
    var theMonthObject = document.all.item(theName + "_MonthList");
    var theDayObject = document.all.item(theName + "_DayList");

    var theHourObject = document.all.item(theName + "_HourInput");
    var theMinuteObject = document.all.item(theName + "_MinuteInput");
    var theSecondObject = document.all.item(theName + "_SecondInput");
	if (isNaN(isNow)||isNow==null)
		isNow = false;
	if (this.hasTime&&isNow){
		Now = new Date();
		theHourObject.value=this.formatTime(Now.getHours());
		theMinuteObject.value=this.formatTime(Now.getMinutes());
		theSecondObject.value=this.formatTime(Now.getSeconds());
	}
    var tmpName = theObject.id.substr(theObject.id.lastIndexOf("_"));
    switch (tmpName){
      case "_goPreviousMonth": //go previous month button
	    theObject.disabled = true;
		if (this.hasTime)
			this.CreateMonth(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10) - 1, parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
		else
			this.CreateMonth(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10) - 1, parseInt(theDayObject.value, 10));
	    theObject.disabled = false;
	    break;
	  case "_goNextMonth": //go next month button
	    theObject.disabled = true;
		if (this.hasTime)
			this.CreateMonth(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10) + 1, parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
		else
			this.CreateMonth(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10) + 1, parseInt(theDayObject.value, 10));
	    theObject.disabled = false;
	    break;
	  case "_YearList": //year list
		if (this.hasTime)
			this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
		else
			this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10));
	    break;
	  case "_MonthList": //month list
		if (this.hasTime)
			this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
		else
			this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10));
	    break;
	  case "_HourInput": //Hour Input		
		if (isNaN(theHourObject.value)||theHourObject.value==null||theHourObject.value=="")
			break;
		if (isNaN(theMinuteObject.value)||theMinuteObject.value==null||theMinuteObject.value=="")
			break;
		if (isNaN(theSecondObject.value)||theSecondObject.value==null||theSecondObject.value=="")
			break;
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  case "_MinuteInput": //Minute Input
		if (isNaN(theHourObject.value)||theHourObject.value==null||theHourObject.value=="")
			break;
		if (isNaN(theMinuteObject.value)||theMinuteObject.value==null||theMinuteObject.value=="")
			break;
		if (isNaN(theSecondObject.value)||theSecondObject.value==null||theSecondObject.value=="")
			break;
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  case "_SecondInput": //Second Input
		if (isNaN(theHourObject.value)||theHourObject.value==null||theHourObject.value=="")
			break;
		if (isNaN(theMinuteObject.value)||theMinuteObject.value==null||theMinuteObject.value=="")
			break;
		if (isNaN(theSecondObject.value)||theSecondObject.value==null||theSecondObject.value=="")
			break;
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  case "_TimeInputUp": //TimeInputUp button
		this.controlTime();
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  case "_TimeInputDown": //TimeInputDown button
		this.controlTime();
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  case "_TimeInput": //_TimeInput list
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10), parseInt(theHourObject.value, 10), parseInt(theMinuteObject.value, 10), parseInt(theSecondObject.value, 10));
	    break;
	  default:
	    return;
    }
  }
////////////////////////////////////////////////////////////
 this.getNowTime=function(){
  var objDate = new Date();
  return this.formatTime(objDate.getHours())+":"+
    this.formatTime(objDate.getMinutes())+":"+
    this.formatTime(objDate.getSeconds());
 }
 this.play = function() {
  this.timer = setInterval(this.name+".playback()",1000);
 }
 this.formatTime = function(sTime) {
  sTime = ("0"+sTime);
  return sTime.substr(sTime.length-2);
 }
 this.playback = function() {
  var objDate = new Date();
  var arrDate = [objDate.getHours(),objDate.getMinutes(),objDate.getSeconds()];
  var objMinute = document.getElementsByName(this.fName);
  for (var i=0;i<objMinute.length;i++) {
   objMinute[i].value = this.formatTime(arrDate[i])
  }
 }
 
 this.setForObjValue=function(){
  //eval("document.all."+forObj+".value=this.getTime()");
	var tt=this.getTime();
 }
 this.prevent = function(obj) {
  clearInterval(this.timer);
  this.setFocusObj(obj);
  var value = parseInt(obj.value,10);
  var radix = parseInt(obj.radix,10)-1;
  if (obj.value>radix||obj.value<0) {
   obj.value = obj.value.substr(0,1);
  }
 }
 this.controlTime = function(cmd) {
  event.cancelBubble = true;
  if (!this.fObj) return;
  clearInterval(this.timer);

⌨️ 快捷键说明

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