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

📄 calendar.js

📁 这是我上次报java培训时
💻 JS
📖 第 1 页 / 共 3 页
字号:
	  var theDate = new Date(this.GetTextDate(this.Source.value));
	  if (isNaN(theDate)){
	    this.Source.value = "";
	  }else{
	    this.Source.value = this.SetDateFormat(theDate.getFullYear(), theDate.getMonth(), theDate.getDate());
	  }
	  this.Source = null;
    }
  }
  this.InitialMonthView = function( ){
    var theName = this.Name;
    var theValue = this.Source.value;
    var theCurrentDate = new Date(this.GetTextDate(theValue));
	if (isNaN(theCurrentDate)){
	  theCurrentDate = new Date();
	}
    var theDivHTML = "<div  style='visibility:hidden' id=\"" + theName + "_MonthView\" onBlur=\"document.jsMonthView.DeleteMonthGrid();\">";
    theDivHTML += "    <table width=\"" + this.Width.toString() + "\" height=\"" + this.Height.toString() + "\" style=\"" + this.MonthGridStyle + "\" cellpadding=\"0\" cellspacing=\"0\">";
    theDivHTML += "      <tr>";
    theDivHTML += "        <td align=\"center\" valign=\"top\">";
    theDivHTML += "          <table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    theDivHTML += "            <tr align=\"center\" style=\"" + this.HeaderStyle + "\">";
    theDivHTML += "              <td>";
    theDivHTML += "                <input type=\"button\" tabIndex=\"-1\" style=\"" + this.MonthBtStyle + "\" id=\"" + theName + "_goPreviousMonth\" value=\"" + this.PreviousMonthText + "\" onClick=\"document.jsMonthView.UpdateMonthGrid(this)\" onBlur=\"document.jsMonthView.DeleteMonthGrid()\">";
    theDivHTML += "              </td>";
    theDivHTML += "              <td>";
    theDivHTML += "                <select id=\"" + theName + "_MonthList\">";
    theDivHTML += "                </select>";
    theDivHTML += "              </td>";
    theDivHTML += "              <td>";
    theDivHTML += "                <select id=\"" + theName + "_YearList\">";
    theDivHTML += "                </select>";
    theDivHTML += "                <input type=\"hidden\" id=\"" + theName + "_DayList\" value=\"1\">";
    theDivHTML += "              </td>";
    theDivHTML += "              <td>";
    theDivHTML += "                <input type=\"button\" tabIndex=\"-1\" style=\"" + this.MonthBtStyle + "\" id=\"" + theName + "_goNextMonth\" value=\"" + this.NextMonthText + "\" onClick=\"document.jsMonthView.UpdateMonthGrid(this)\" onBlur=\"document.jsMonthView.DeleteMonthGrid()\">";
    theDivHTML += "              </td>";
    theDivHTML += "            </tr>";
    theDivHTML += "            <tr>";
    theDivHTML += "              <td colspan=\"4\" bgcolor=\"" + this.UnselectBgColor + "\">";
    theDivHTML += "                <div id=\"" + theName + "_MonthGrid\"><br></div>";
    theDivHTML += "              </td>";
    theDivHTML += "            </tr>";
    theDivHTML += "          </table>";
    theDivHTML += "        </td>";
    theDivHTML += "      </tr>";
    theDivHTML += "    </table>";
    theDivHTML += "  </div>";
    document.body.insertAdjacentHTML("beforeEnd", theDivHTML);
    theDivObject = document.all.item(theName + "_MonthView");
    theDivObject.style.position = "absolute";
    theDivObject.style.posLeft = this.GetoffsetLeft(this.Source);
    theDivObject.style.posTop = this.GetoffsetTop(this.Source) + this.Source.offsetHeight;
    this.CreateYearList(this.MinYear, this.MaxYear);
    this.CreateMonthList();
    this.CreateMonthGrid(theCurrentDate.getFullYear(), theCurrentDate.getMonth(), theCurrentDate.getDate());
  }
}
function CreateMonthView(theTextObject){ //the month view create interface, fire at element's onFocus event
  if (theTextObject.readOnly == true){
    return;
  }
  if (document.jsMonthView != null){
    if (document.jsMonthView.Source == theTextObject){
	  return;
	}else{
      document.jsMonthView.DeleteMonthGrid();
    }
  }
  document.jsMonthView = new DefineMonthView(theTextObject);
  //insert your code, change the month view propertiy
  //example:
  //  document.jsMonthView.DateFormat = "<MMM> <d>,<yyyy>";
  document.jsMonthView.InitialMonthView();
  theTextObject.select();
  document.jsMonthView.Show();
}
function DeleteMonthView(theTextObject){ //the month view delete interface, fire at element's onBlur event
  if (document.jsMonthView == null){
    return;
  }
  document.jsMonthView.DeleteMonthGrid();
  if (document.jsMonthView.Source == null){
    document.jsMonthView = null;
  }
}
</script>

<script language="JavaScript">
// Written by cloudchen, 2004/03/15
// @name:必须:时间控件名称,自定义,不可重复
// @forObj:必须:对话数据项控件名称,不允许重复
// @fName:可选:时间控件组件,不允许重复
// last modfiy by 农民程序员(191301587@163.com) 2004年9月7日 19:01:02
function timeControl(name,forObj,fTime,fName) {
 this.name = name;
 this.fName = fName || "mctr_input_"+this.name;
 
 this.timer = null;
 this.fObj = null;
 this.time = fTime;
 
 this.toString = function() {
  var objDate = new Date();
  if (this.time!=null && this.time!="") {
	  objDate.setHours(this.time.substr(0,2));
	  objDate.setMinutes(this.time.substr(3,2));
	  objDate.setSeconds(this.time.substr(6,2));
  }
  //
  var sMinute_Common = "class=\"mctr_input\" maxlength=\"2\" name=\""+this.fName+"\" onfocus=\""+
   this.name+".setFocusObj(this)\" onblur=\""+this.name+".setTime(this)\" onkeyup=\""+
   this.name+".prevent(this)\" onkeypress=\"if (!/[0-9]/.test(String.fromCharCode(event.keyCode)))event.keyCode=0\""+
   " onpaste=\"return false\" ondragenter=\"return false\" style=\"ime-mode:disabled\" onPropertychange=\""+
   this.name+".setForObjValue()\"";
  //
  var sButton_Common = "class=\"mctr_arrow\" onfocus=\"this.blur()\" onmouseup=\""+this.name+".controlTime()\" disabled";
  
  var str = "";
  str +=" <style type=\"text/css\">"
  str +=" .mctr_frameborder {"
  str +="  border-left: 1px inset #D4D0C8;"
  str +="  border-top: 1px inset #D4D0C8;"
  str +="  border-right: 1px inset #D4D0C8;"
  str +="  border-bottom: 1px inset #D4D0C8;"
  str +="  width: 130px;"
  str +="  height: 20px;"
  str +="  background-color: #FFFFFF;"
  str +="  overflow: hidden;"
  str +="  text-align: left;"       //text-align: right;
  str +="  vertical-align: text-top;"       
  str +="  font-family: \"Tahoma\";"
  str +="  font-size: 14px;"
  str +=" }"
  str +=" .mctr_arrow {"
  str +="  width: 16px;"
  str +="  height: 10px;"
  str +="  font-family: \"Webdings\";"
  str +="  font-size: 9px;"
  str +="  line-height: 2px;"
  str +="  background-color: #FFFFFF;"
  str +="  padding-left: 2px;"
  str +="  cursor: default;"
  str +=" }"
  str +=" .mctr_table {"
  str +="  padding-top: 0px;"
  str +="  padding-right: 0px;"
  str +="  padding-bottom: 0px;"
  str +="  padding-left: 0px;"
  str +=" }"
  str +=" .mctr_input {"
  str +="  width: 18px;"
  str +="  height: 16px;"
  str +="  border: 0px solid black;"
  str +="  font-size: 12px;"
  str +="  text-align: right;"
  str +="  background-color: transparent;"
  str +=" }"
  str +=" </style>";
  str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"mctr_table\">"
  str += "<tr class=\"mctr_table\">"
  str += "<td class=\"mctr_table\">"
  str += "<span class=\"mctr_frameborder\">"
  str += "<input radix=\"24\" value=\""+this.formatTime(objDate.getHours())+"\" "+sMinute_Common+">:"
  str += "<input radix=\"60\" value=\""+this.formatTime(objDate.getMinutes())+"\" "+sMinute_Common+">:"
  str += "<input radix=\"60\" value=\""+this.formatTime(objDate.getSeconds())+"\" "+sMinute_Common+">"
  str += "</span>"
  str += "</td>"
  str += "<td class=\"mctr_table\">"
  str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"mctr_table\">"
  str += "<tr class=\"mctr_table\"><td class=\"mctr_table\"><button id=\""+this.fName+"_up\" "+sButton_Common+">5</button></td></tr>"
  str += "<tr class=\"mctr_table\"><td class=\"mctr_table\"><button id=\""+this.fName+"_down\" "+sButton_Common+">6</button></td></tr>"
  str += "</table>"
  str += "</td>"
  str += "<td>"
  str += "<input type=\"Text\" name=\""+forObj+"\" id=\""+forObj+"\" value=\""+this.getNowTime(objDate)+"\" style=\"display:'none'\">"
  str += "</td>"
  str += "</tr>"
  str += "</table>"
  return str;
 }
 this.getNowTime=function(objDate){
  //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()");
 }
 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);
  var cmd = event.srcElement.innerText=="5"?true:false;
  var i = parseInt(this.fObj.value,10);
  var radix = parseInt(this.fObj.radix,10)-1;
  if (i==radix&&cmd) {
   i = 0;
  } else if (i==0&&!cmd) {
   i = radix;
  } else {
   cmd?i++:i--;
  }
  this.fObj.value = this.formatTime(i);
  this.fObj.select();
 }
 this.setTime = function(obj) {
  obj.value = this.formatTime(obj.value);
 }
 this.setFocusObj = function(obj) {
  eval("document.all."+this.fName+"_up").disabled = eval("document.all."+this.fName+"_down").disabled = false;
  this.fObj = obj;
 }
 this.getTime = function() {
  var arrTime = new Array(2);
  for (var i=0;i<document.getElementsByName(this.fName).length;i++) {
   arrTime[i] = document.getElementsByName(this.fName)[i].value;
  }
  return arrTime.join(":")
 }
 this.setInitControl=function(){
  var iTime=eval("document.all."+forObj+".value");
  var arrTime=new Array();
  arrTime=str2Array(iTime,":");
  for (var i=0;i<arrTime.length;i++){
   document.getElementsByName(this.fName)[i].value=arrTime[i];
  }
 }
}
//将字符串str按照字符串ch拆分产生数组
function str2Array(str,ch)
{
 var a=new Array();
 var i=0,j=-1,k=0;
 while (i<str.length)
 {  
  j=str.indexOf(ch,j+1);   
  if (j!=-1)
  {
   if (j==0){a[k]="";}else{a[k]=str.substring(i,j);}
   i=j+1;
  }else
  {
   a[k]=str.substring(i,str.length);
   i=str.length;
  }
  k++;
 }
 return a;
}
</script>




    <script>
function isTime(str){
  var a = str.match(/^(\d{0,2}):(\d{0,2}):(\d{0,2})$/);
  if (a == null) return false;
  if (a[1]>=24 || a[2]>=60 || a[3]>=60) return false;
  return true;
}
function isDateTime(str){
  var a = str.match(/^(\d{0,4})-(\d{0,2})-(\d{0,2}) (\d{0,2}):(\d{0,2}):(\d{0,2})$/);
  if (a == null) return false;
  if ( a[2]>=13 || a[3]>=32 || a[4]>=24 || a[5]>=60 || a[6]>=60) return false;
  return true;
}
function isDate(str){
  var a = str.match(/^(\d{0,4})-(\d{0,2})-(\d{0,2})$/);
  if (a == null) return false;
  if ( a[2]>=13 || a[3]>=32 || a[4]>=24) return false;
  return true;
}
function validate(obj,type){
var range=obj.createTextRange(); 
var text = range.text;
var selrange = document.selection.createRange();
var seltext = selrange.text;
var startpos = 0,endpos = 0;
while(selrange.compareEndPoints("StartToStart",range)>0){ 
  selrange.moveStart("character",-1);  
  startpos ++;
}
while(selrange.compareEndPoints("EndToStart",range)>0){ 
  selrange.moveEnd("character",-1);  
  endpos ++;
}
if(event.keyCode>=48){ 
  var keytext = String.fromCharCode(event.keyCode);
  text = text.substring(0,startpos) + keytext + text.substring(endpos,text.length);
}else if(event.keyCode == 46){//delete
  if(startpos == endpos)text = text.substring(0,startpos) + text.substring(startpos+1,text.length);
  else text = text.substring(0,startpos) + text.substring(endpos,text.length);
}else if(event.keyCode == 8){
  if(startpos == endpos)text = text.substring(0,startpos-1) + text.substring(startpos,text.length);
  else text = text.substring(0,startpos) + text.substring(endpos,text.length);
}
if(event.keyCode == 45){
  event.returnValue = false;
  return;
}
var valid;
switch(type){
  case 1:valid = isDate(text);break;
  case 2:valid = isTime(text);break;
  case 3:valid = isDateTime(text);break;
  default:valid = false;
}
if(!valid){
 event.returnValue = false;
}
}
</script>

⌨️ 快捷键说明

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