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

📄 calendar.js

📁 这是我上次报java培训时
💻 JS
📖 第 1 页 / 共 3 页
字号:
	  if (year_at == -1){
	    year_at = tmpDate.indexOf("<yy>");
	  }
	  month_at = tmpDate.indexOf("<MMMMMM>");
	  if (month_at == -1){
	    month_at = tmpDate.indexOf("<MMM>");
	  }
	  if (month_at == -1){
	    month_at = tmpDate.indexOf("<mm>");
	  }
	  if (month_at == -1){
	    month_at = tmpDate.indexOf("<m>");
	  }
	  day_at = tmpDate.indexOf("<dd>");
	  if (day_at == -1){
	    day_at = tmpDate.indexOf("<d>");
	  }
	  if ((year_at>month_at)&&(year_at>day_at)){
	    find_tag="001"
	  }
	  if ((year_at>month_at)&&(year_at<=day_at)){
	    find_tag="010";
	  }
	  if ((year_at<=month_at)&&(year_at>day_at)){
	    find_tag="010";
	  }
	  if ((year_at<=month_at)&&(year_at<=day_at)){
	    find_tag="100";
	  }
	  switch (find_tag){
	    case "100":
	      tmpYear = parseInt(aryDate[0],10);
		  one_at = parseInt(aryDate[1],10);
		  two_at = parseInt(aryDate[2],10);
		  break;
	    case "010":
		  one_at = parseInt(aryDate[0],10);
	      tmpYear = parseInt(aryDate[1],10);
		  two_at = parseInt(aryDate[2],10);
		  break;
	    case "001":
		  one_at = parseInt(aryDate[0],10);
		  two_at = parseInt(aryDate[1],10);
	      tmpYear = parseInt(aryDate[2],10);
		  break;
	  }
	  tmpYear = this.GetFormatYear(tmpYear);
    }
    if (find_tag!="000"){
      if ((one_at>12)&&(two_at>12)){
	    return(defDate);
	  }
	  if (one_at<=12){
	    if (two_at > this.GetMonthDays(tmpYear,one_at-1)){
	      return(new Date(tmpYear, one_at-1, this.GetMonthDays(tmpYear,one_at-1)));
	    }
	    if (two_at>12){
	      return(new Date(tmpYear, one_at-1, two_at));
	    }
	  }
	  if (two_at<=12){
	    if (one_at > this.GetMonthDays(tmpYear,two_at-1)){
	      return(new Date(tmpYear, two_at-1, this.GetMonthDays(tmpYear,two_at-1)));
	    }
	    if (one_at>12){
	      return(new Date(tmpYear, two_at-1, one_at));
	    }
	  }
	  if ((one_at<=12)&&(two_at<=12)){
	    tmpMonth = one_at-1;
	    tmpDay = two_at;
	    tmpDate = this.DateFormat;
	    month_at = tmpDate.indexOf("<MMMMMM>");
	    if (month_at == -1){
	      month_at = tmpDate.indexOf("<MMM>");
	    }
	    if (month_at == -1){
	      month_at = tmpDate.indexOf("<mm>");
	    }
	    if (month_at == -1){
	      month_at = tmpDate.indexOf("<m>");
	    }
	    day_at = tmpDate.indexOf("<dd>");
	    if (day_at == -1){
	      day_at = tmpDate.indexOf("<d>");
	    }
	    if (month_at >= day_at){
	      tmpMonth = two_at-1;
		  tmpDay = one_at;
	    }
 	    return(new Date(tmpYear, tmpMonth, tmpDay));
	  }
    }
  }
  this.CreateYearList = function(MinYear, MaxYear){ //create year list
    var theName = this.Name;
    var theYearObject = document.all.item(theName + "_YearList");
	if (theYearObject == null){
	  return;
	}
    var theYear = 0;
    var theYearHTML = "<select id=\"" + theName + "_YearList\" style=\"" + this.YearListStyle + "\" tabIndex=\"-1\" onChange=\"document.jsMonthView.UpdateMonthGrid(this)\" onBlur=\"document.jsMonthView.DeleteMonthGrid()\">";
    for (theYear = MinYear; theYear <= MaxYear; theYear++){
      theYearHTML += "<option value=\"" + theYear.toString() + "\">" + theYear.toString() + "</option>";
    }
    theYearHTML += "</select>";
    theYearObject.outerHTML = theYearHTML;
  }
  this.CreateMonthList = function( ){ //create month list
	var theName = this.Name;
    var theMonthObject = document.all.item(theName + "_MonthList");
	if (theMonthObject == null){
	  return;
	}
    var theMonth = 0;
    var theMonthHTML = "<select id=\"" + theName + "_MonthList\" style=\"" + this.MonthListStyle + "\" tabIndex=\"-1\" onChange=\"document.jsMonthView.UpdateMonthGrid(this)\" onBlur=\"document.jsMonthView.DeleteMonthGrid()\">";
    for (theMonth = 0; theMonth < 12; theMonth++){
      theMonthHTML += "<option value=\"" + theMonth.toString() + "\">" + this.MonthName[theMonth] + "</option>";
    }
    theMonthHTML +="</select>";
    theMonthObject.outerHTML = theMonthHTML;
  }
  this.setDayList = function(theYear, theMonth, theDay){ //set the month view show a date
	var theName = this.Name;
    var theDayObject = document.all.item(theName + "_DayList");
	if (theDayObject == null){
	  return;
	}
    theDayObject.value = theDay.toString();
    var theFirstDay = new Date(theYear, theMonth, 1);
    var theCurrentDate = new Date();
    var theWeek = theFirstDay.getDay();
    if (theWeek == 0){
      theWeek = 7;
    }
    var theLeftDay = 0;
    if (theMonth == 0){
      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() +
	    ");"+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() + ");\">";
    theStyle = "border:" + this.DayBdWidth + "px solid " + this.TodayBdColor + ";";
    theDayHTML += "			<td style=\"" + theStyle + "\"><br></td>";
    theDayHTML += "			<td colspan=\"6\"> " + this.TodayTitle + " " + this.SetDateFormat(theCurrentDate.getFullYear(), theCurrentDate.getMonth(), theCurrentDate.getDate()) + "</td>";
    theDayHTML += "		</tr>";
    theDayHTML += "	</table>";
    var theMonthGrid = document.all.item(theName + "_MonthGrid");
    theMonthGrid.innerHTML = theDayHTML;
  }
  this.CreateMonthGrid = function(theYear, theMonth, theDay){ //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;
    this.setDayList(tmpYear, tmpMonth, tmpDay);
    theTextObject.value = this.SetDateFormat(tmpYear, tmpMonth, tmpDay);
    theTextObject.select();
  }
  this.UpdateMonthGrid = function(theObject){ //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 tmpName = theObject.id.substr(theObject.id.lastIndexOf("_"));
    switch (tmpName){
      case "_goPreviousMonth": //go previous month button
	    theObject.disabled = true;
	    this.CreateMonthGrid(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;
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10) + 1, parseInt(theDayObject.value, 10));
	    theObject.disabled = false;
	    break;
	  case "_YearList": //year list
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10));
	    break;
	  case "_MonthList": //month list
	    this.CreateMonthGrid(parseInt(theYearObject.value, 10), parseInt(theMonthObject.value, 10), parseInt(theDayObject.value, 10));
	    break;
	  default:
	    return;
    }
  }

  this.Show = function(){
    var theName = this.Name;
    var theDivObject = document.all.item(theName + "_MonthView");
    if (theDivObject == null){ return;}
    theDivObject.style.visibility ="visible";
  }


  //删除对象
  this.DeleteMonthGrid = function( ){ //check document focus, if blur this.Source then delete this
    var theName = this.Name;
    var theDivObject = document.all.item(theName + "_MonthView");
    if (theDivObject == null){
      return;
    }
    var tmpObject = document.activeElement;
    while (tmpObject != null){
      if (tmpObject == this.Source){
	    return;
	  }
      //if (tmpObject.id == theName + "_MonthView"){
      //  return;
      //}
	  //if (tmpObject.id == theName + "_MonthGrid"){
	  //  return;
	  //}
	  if (tmpObject.id == theName + "_goPreviousMonth"){
	    return;
	  }
	  if (tmpObject.id == theName + "_goNextMonth"){
	    return;
	  }
	  if (tmpObject.id == theName + "_YearList"){
	    return;
	  }
	  if (tmpObject.id == theName + "_MonthList"){
	    return;
	  }
	  if (tmpObject.id == theName + "_DayList"){
	    return;
	  }
      tmpObject = tmpObject.parentElement;
    }
    if (tmpObject == null){ //delete the month view
      theDivObject.outerHTML = "";

⌨️ 快捷键说明

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