当前位置:编程学习 > asp >>

非常好用的日期选择器建议入精华《二》

答案:4。calendar.js
var gdCtrl = new Object();
var goSelectTag = new Array();
var gcGray = "#808080";
var gcToggle = "#ffff00";
var gcBG = "#99CCFF";
var previousObject = null;

var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();

var gCalMode = "";
var gCalDefDate = "";

var CAL_MODE_NOBLANK = "2";

function fSetDate(iYear, iMonth, iDay){
  //VicPopCal.style.visibility = "hidden";
  if ((iYear == 0) && (iMonth == 0) && (iDay == 0)){
      gdCtrl.value = "";
  }else{
      iMonth = iMonth + 100 + "";
      iMonth = iMonth.substring(1);
      iDay   = iDay + 100 + "";
      iDay   = iDay.substring(1);
      gdCtrl.value = iYear+"-"+iMonth+"-"+iDay;
  }
  
  for (i in goSelectTag)
      goSelectTag[i].style.visibility = "visible";
  goSelectTag.length = 0;
  
  window.returnValue=gdCtrl.value;
  window.close();
}

function HiddenDiv()
{
    var i;
  VicPopCal.style.visibility = "hidden";
  for (i in goSelectTag)
      goSelectTag[i].style.visibility = "visible";
  goSelectTag.length = 0;

}
function fSetSelected(aCell){
  var iOffset = 0;
  var iYear = parseInt(tbSelYear.value);
  var iMonth = parseInt(tbSelMonth.value);
  
  aCell.bgColor = gcBG;
  with (aCell.children["cellText"]){
      var iDay = parseInt(innerText);
      if (color==gcGray)
        iOffset = (Victor<10)?-1:1;

    /*** below temp patch by maxiang ***/
    if( color == gcGray ){
        iOffset = (iDay < 15 )?1:-1;
    }
    /*** above temp patch by maxiang ***/

    iMonth += iOffset;
    if (iMonth<1) {
        iYear--;
        iMonth = 12;
    }else if (iMonth>12){
        iYear++;
        iMonth = 1;
    }
  }
  fSetDate(iYear, iMonth, iDay);
}

function Point(iX, iY){
    this.x = iX;
    this.y = iY;
}

function fBuildCal(iYear, iMonth) {
  var aMonth=new Array();
  for(i=1;i<7;i++)
      aMonth[i]=new Array(i);
  
  var dCalDate=new Date(iYear, iMonth-1, 1);
  var iDayOfFirst=dCalDate.getDay();
  var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
  var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
  var iDate = 1;
  var iNext = 1;

  for (d = 0; d < 7; d++)
    aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
  for (w = 2; w < 7; w++)
      for (d = 0; d < 7; d++)
        aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++);
  return aMonth;
}

function fDrawCal(iYear, iMonth, iCellHeight, sDateTextSize) {
  var WeekDay = new Array("日","一","二","三","四","五","六");
  var styleTD = " bgcolor='"+gcBG+"' bordercolor='"+gcBG+"' valign='middle' align='center' height='"+iCellHeight+"' style='font-size:12px; ";

  with (document) {
    write("<tr>");
    for(i=0; i<7; i++)
        write("<td "+styleTD+" color:#990099' >" + WeekDay[i] + "</td>");
    write("</tr>");

      for (w = 1; w < 7; w++) {
        write("<tr>");
        for (d = 0; d < 7; d++) {
            write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'>");
            write("<font id=cellText ><b> </b></font>");
            write("</td>")
        }
        write("</tr>");
    }
  }
}

function fUpdateCal(iYear, iMonth) {
  myMonth = fBuildCal(iYear, iMonth);
  var i = 0;
  for (w = 0; w < 6; w++)
    for (d = 0; d < 7; d++)
        with (cellText[(7*w)+d]) {
            Victor = i++;
            if (myMonth[w+1][d]<0) {
                color = gcGray;
                innerText = -myMonth[w+1][d];
            }else{
                // Modified by maxiang for we need
                // Saturday displayed in blue font color.
                //color = ((d==0)||(d==6))?"red":"black";
                if( d == 0 ){
                    color = "red";
                }else if( d == 6 ){
                    color = "blue";
                }else{
                    color = "black";
                }
         &nbs

上一个:一个通用验证javascript函数
下一个:模拟QQ的下拉列表选择图象(小白完善版)

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,