查看效果:日历效果
var myc_x,myc_y;
var myc_timeset=null,myc_timeset1=null;
var divobj=null;
var inputname;
function mycalendar() //构建对象
{
var mydate = new date();
this.year = mydate.getfullyear();
this.month = mydate.getmonth()+1;
this.date = mydate.getdate();
this.format=yyyy-mm-dd;
this.style = mystyle(1);
this.show = createcalendar;
this.input = createinput;
}
function mystyle(num) //设置样式
{
if(!num||isnan(num)){alert('参数不对,采用默认样式!');num=1;}
var style = new array();
style[1]=.week{background-color:#dfdfff;font-size:12px;width:140px;}
+.ds{width:140px;font-size:12px;cursor:hand}
+.mover{border:1px solid black;background-color:#f4f4f4;}
+.move1{border:1px solid #5d5d5d;background-color:#f4f4f4;color:#909eff;font-size:12px}
+.tit{background-color:#909eff;width:140px;font-size:12px;color:white;cursor:default}
+.cs{position:absolute;border:1px solid #909eff;width:142px;left:0px;top:0px;z-index:9999;}
+.shadow{position:absolute;left:0px;top:0px;font-family: arial black;font-size:50px;color:#d4d4d4;z-index:1;text-align:center;};
document.write();
}
function createcalendar()
{
var week = new array('日','一','二','三','四','五','六');
document.write(
//创建头部
document.write(
7 | 3 | 4 | 8 |
//创建星期条目
document.write(
+week[i]+ | );
//创建日期条目
document.write(
); |
//建建水印
document.write(
//创建选择图层
document.write(
);document.write(
//显示日期
showdate(this.year,this.month);
myc_div.style.display='none';
}
function getvalue(obj,value)
{
eval(obj).value=parseint(myc_top.cells[2].innertext)+-+parseint(myc_top.cells[3].innertext)+-+value;
}
function showdate(year,month)
{
var mydate = new date(year,month-1,1);
var today = new date();
var day = mydate.getday();
var length = new array(31,30,31,30,31,30,31,31,30,31,30,31);
length[1] = ((year%4==0)&&(year%100!=0)||(year%400==0))?29:28;
for(i=0;i for(i=0;i { myc.cells[i+day].innerhtml = (i+1); if(new date(year,month-1,i+1).getday()==6||new date(year,month-1,i+1).getday()==0){myc.cells[i+day].style.color='red';} } myc_top.cells[2].innertext=year+年; myc_top.cells[3].innertext=month+月; with(myc.parentnode.previoussibling.style) { pixelleft=myc.offsetleft; pixeltop=myc.offsettop; height = myc.clientheight; width = myc.clientwidth; } myc.parentelement.parentelement.style.height=myc.parentelement.offsetheight; myc.parentelement.previoussibling.innerhtml=year; } //一些附加函数-------------------- //---------begin------------------- function mover(obj){obj.classname = 'mover';} function mout(obj){if(obj.classname=='mover')obj.classname = '';} function addyear(){var year = parseint(myc_top.cells[2].innertext);var month = parseint(myc_top.cells[3].innertext); year++;showdate(year,month);} function addmonth(){var year = parseint(myc_top.cells[2].innertext);var month = parseint(myc_top.cells[3].innertext);month++;if(month>12){month=1;year++;}showdate(year,month);} function cutyear(){var year = parseint(myc_top.cells[2].innertext);var month = parseint(myc_top.cells[3].innertext);year--;showdate(year,month);} function cutmonth(){var year = parseint(myc_top.cells[2].innertext);var month = parseint(myc_top.cells[3].innertext);month--;if(month<1){month=12;year--;}showdate(year,month);} function divs(obj) { if(obj!=divobj) { obj.style.backgroundcolor=#909eff; obj.style.color='black'; } if(divobj!=null) { divobj.style.backgroundcolor=''; divobj.style.color=''; } divobj = obj; } function divshow(obj) { if (myc_timeset!=null) cleartimeout(myc_timeset); obj.style.display='block'; } function divhidden(obj){myc_timeset=window.settimeout(function(){obj.style.display='none'},500);} function createyear(year,obj)//创建年份选择 { var ystr; var odiv; ystr= ystr+= for(i=year-10;i if(year==i) ystr+= else ystr+= ystr+= ystr+= odiv = myc.parentelement.nextsibling; odiv.innerhtml=''; odiv.innerhtml = ystr; showdiv(odiv,obj.offsettop+obj.offsetheight,obj.offsetleft); } function createmonth(month,obj)//创建月份选择 { var mstr; var odiv; mstr= for(i=1;i<13;i++) if (month==i) mstr+= else mstr+= mstr+=;
; ;
上翻 ;+i+年 ;
+i+年 ;
下翻 ;
; ;
+i+月 ;
+i+月
odiv = myc.parentelement.nextsibling;
odiv.innerhtml='';
odiv.innerhtml = mstr;
showdiv(odiv,obj.offsettop+obj.offsetheight,obj.offsetleft);
}
function showdiv(obj,top,left)
{
obj.style.pixeltop=top;
obj.style.pixelleft=left;
}
function mycmove(obj)
{
if(event.button==1)
{
var x = obj.clientleft;
var y = obj.clienttop;
obj.style.pixelleft= x+(event.x-myc_x);
obj.style.pixeltop= y+(event.y-myc_y);
window.status=myc_y;
}
}
function showdiv2(obj)
{
inputname=obj.name;
var e=obj;
var ot = obj.offsettop;
var ol=obj.offsetleft;
while(obj=obj.parentelement){ot+=obj.offsettop;ol+=obj.offsetleft;}
myc_div.style.pixeltop=ot+e.offsetheight;
myc_div.style.pixelleft=ol;
myc_div.style.display=block;
}
function createinput(name)
{myc_div.style.display='none';
document.write();
}
// --------------end ---------------------
var mycalendar=new mycalendar;
mycalendar.year=2005;
mycalendar.show();
mycalendar.input(txt1);