JavaScript极品小日历

代码如下:
<script language='javascript' src='http://www.adsenser.org/js/calendar.js'></script> <input type="text" name=date title="单击弹出日历" style='width:80;cursor:pointer;' onfocus="javascript:calendar()">
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]

其中用到一个Calendar.js文件代码如下:

1document.write("<divid=meizzCalendarLayerstyle='position:absolute;z-index:9999;width:144;height:193;display:none'>");
2document.write("<iframename=meizzCalendarIframescrolling=noframeborder=0width=100%height=100%></iframe></div>");
3functionwriteIframe(){
4varstrIframe="<html><head><metahttp-equiv='Content-Type'content='text/html;charset=gb2312'><style>"+
5"*{font-size:12px;font-family:宋体}"+
6".bg{color:"+WebCalendar.lightColor+";cursor:default;background-color:"+WebCalendar.darkColor+";}"+
7"table#tableMain{width:142;height:180;}"+
8"table#tableWeektd{color:"+WebCalendar.lightColor+";}"+
9"table#tableDaytd{font-weight:bold;}"+
10"td#meizzYearHead,td#meizzYearMonth{color:"+WebCalendar.wordColor+"}"+
11".out{text-align:center;border-top:1pxsolid"+WebCalendar.DarkBorder+";border-left:1pxsolid"+WebCalendar.DarkBorder+";"+
12"border-right:1pxsolid"+WebCalendar.lightColor+";border-bottom:1pxsolid"+WebCalendar.lightColor+";}"+
13".over{text-align:center;border-top:1pxsolid#FFFFFF;border-left:1pxsolid#FFFFFF;"+
14"border-bottom:1pxsolid"+WebCalendar.DarkBorder+";border-right:1pxsolid"+WebCalendar.DarkBorder+"}"+
15"input{border:1pxsolid"+WebCalendar.darkColor+";padding-top:1px;height:18;cursor:hand;"+
16"color:"+WebCalendar.wordColor+";background-color:"+WebCalendar.btnBgColor+"}"+
17"</style></head><bodyonselectstart='returnfalse'style='margin:0px'oncontextmenu='returnfalse'><formname=meizz>";
18if(WebCalendar.drag){strIframe+="<scr"+"iptlanguage=javascript>"+
19"vardrag=false,cx=0,cy=0,o=parent.WebCalendar.calendar;functiondocument.onmousemove(){"+
20"if(parent.WebCalendar.drag&&drag){if(o.style.left=='')o.style.left=0;if(o.style.top=='')o.style.top=0;"+
21"o.style.left=parseInt(o.style.left)+window.event.clientX-cx;"+
22"o.style.top=parseInt(o.style.top)+window.event.clientY-cy;}}"+
23"functiondocument.onkeydown(){switch(window.event.keyCode){case27:parent.hiddenCalendar();break;"+
24"case37:parent.prevM();break;case38:parent.prevY();break;case39:parent.nextM();break;case40:parent.nextY();break;"+
25"case84:document.forms[0].today.click();break;}window.event.keyCode=0;window.event.returnValue=false;}"+
26"functiondragStart(){cx=window.event.clientX;cy=window.event.clientY;drag=true;}</scr"+"ipt>"}
27strIframe+="<selectname=tmpYearSelectonblur='parent.hiddenSelect(this)'style='z-index:1;position:absolute;top:3;left:18;display:none'"+
28"onchange='parent.WebCalendar.thisYear=this.value;parent.hiddenSelect(this);parent.writeCalendar();'></select>"+
29"<selectname=tmpMonthSelectonblur='parent.hiddenSelect(this)'style='z-index:1;position:absolute;top:3;left:74;display:none'"+
30"onchange='parent.WebCalendar.thisMonth=this.value;parent.hiddenSelect(this);parent.writeCalendar();'></select>"+
31"<tableid=tableMainclass=bgborder=0cellspacing=2cellpadding=0>"+
32"<tr><tdwidth=140height=19bgcolor='"+WebCalendar.lightColor+"'>"+
33"<tablewidth=140id=tableHeadborder=0cellspacing=1cellpadding=0><tralign=center>"+
34"<tdwidth=15height=19class=bgtitle='向前翻1月&#13;快捷键:←'style='cursor:hand'onclick='parent.prevM()'><b>&lt;</b></td>"+
35"<tdwidth=60id=meizzYearHeadtitle='点击此处选择年份'onclick='parent.funYearSelect(parseInt(this.innerText,10))'"+
36"onmouseover='this.bgColor=parent.WebCalendar.darkColor;this.style.color=parent.WebCalendar.lightColor'"+
37"onmouseout='this.bgColor=parent.WebCalendar.lightColor;this.style.color=parent.WebCalendar.wordColor'></td>"+
38"<tdwidth=50id=meizzYearMonthtitle='点击此处选择月份'onclick='parent.funMonthSelect(parseInt(this.innerText,10))'"+
39"onmouseover='this.bgColor=parent.WebCalendar.darkColor;this.style.color=parent.WebCalendar.lightColor'"+
40"onmouseout='this.bgColor=parent.WebCalendar.lightColor;this.style.color=parent.WebCalendar.wordColor'></td>"+
41"<tdwidth=15class=bgtitle='向后翻1月&#13;快捷键:→'onclick='parent.nextM()'style='cursor:hand'><b>&gt;</b></td></tr></table>"+
42"</td></tr><tr><tdheight=20><tableid=tableWeekborder=1width=140cellpadding=0cellspacing=0";
43if(WebCalendar.drag){strIframe+="onmousedown='dragStart()'onmouseup='drag=false'onmouseout='drag=false'";}
44strIframe+="borderColorLight='"+WebCalendar.darkColor+"'borderColorDark='"+WebCalendar.lightColor+"'>"+
45"<tralign=center><tdheight=20>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr></table>"+
46"</td></tr><tr><tdvalign=topwidth=140bgcolor='"+WebCalendar.lightColor+"'>"+
47"<tableid=tableDayheight=120width=140border=0cellspacing=1cellpadding=0>";
48for(varx=0;x<5;x++){strIframe+="<tr>";
49for(vary=0;y<7;y++)strIframe+="<tdclass=outid='meizzDay"+(x*7+y)+"'></td>";strIframe+="</tr>";}
50strIframe+="<tr>";
51for(varx=35;x<39;x++)strIframe+="<tdclass=outid='meizzDay"+x+"'></td>";
52strIframe+="<tdcolspan=3class=outtitle='"+WebCalendar.regInfo+"'><inputstyle='background-color:"+
53WebCalendar.btnBgColor+";cursor:hand;padding-top:4px;width:100%;height:100%;border:0'onfocus='this.blur()'"+
54"type=buttonvalue='&nbsp;&nbsp;关闭'onclick='parent.hiddenCalendar()'></td></tr></table>"+
55"</td></tr><tr><tdheight=20width=140bgcolor='"+WebCalendar.lightColor+"'>"+
56"<tableborder=0cellpadding=1cellspacing=0width=140>"+
57"<tr><td><inputname=prevYeartitle='向前翻1年&#13;快捷键:↑'onclick='parent.prevY()'type=buttonvalue='&lt;&lt;'"+
58"onfocus='this.blur()'style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==1000)'><input"+
59"onfocus='this.blur()'name=prevMonthtitle='向前翻1月&#13;快捷键:←'onclick='parent.prevM()'type=buttonvalue='&lt;&nbsp;'>"+
60"</td><tdalign=center><inputname=todaytype=buttonvalue='Today'onfocus='this.blur()'style='width:50'title='当前日期&#13;快捷键:T'"+
61"onclick=\"parent.returnDate(newDate().getDate()+'/'+(newDate().getMonth()+1)+'/'+newDate().getFullYear())\">"+
62"</td><tdalign=right><inputtitle='向后翻1月&#13;快捷键:→'name=nextMonthonclick='parent.nextM()'type=buttonvalue='&nbsp;&gt;'"+
63"onfocus='this.blur()'><inputname=nextYeartitle='向后翻1年&#13;快捷键:↓'onclick='parent.nextY()'type=buttonvalue='&gt;&gt;'"+
64"onfocus='this.blur()'style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==9999)'></td></tr></table>"+
65"</td></tr><table></form></body></html>";
66with(WebCalendar.iframe)
67{
68document.writeln(strIframe);document.close();
69for(vari=0;i<39;i++)
70{
71WebCalendar.dayObj[i]=eval("meizzDay"+i);
72WebCalendar.dayObj[i].onmouseover=dayMouseOver;
73WebCalendar.dayObj[i].onmouseout=dayMouseOut;
74WebCalendar.dayObj[i].onclick=returnDate;
75}
76}
77}
78functionWebCalendar()//初始化日历的设置
79{
80this.regInfo="WEBCalendarver3.0&#13;关闭的快捷键:[Esc]";
81this.daysMonth=newArray(31,28,31,30,31,30,31,31,30,31,30,31);
82this.day=newArray(39);//定义日历展示用的数组
83this.dayObj=newArray(39);//定义日期展示控件数组
84this.dateStyle=null;//保存格式化后日期数组
85this.objExport=null;//日历回传的显示控件
86this.eventSrc=null;//日历显示的触发控件
87this.inputDate=null;//转化外的输入的日期(d/m/yyyy)
88this.thisYear=newDate().getFullYear();//定义年的变量的初始值
89this.thisMonth=newDate().getMonth()+1;//定义月的变量的初始值
90this.thisDay=newDate().getDate();//定义日的变量的初始值
91this.today=this.thisDay+"/"+this.thisMonth+"/"+this.thisYear;//今天(d/m/yyyy)
92this.iframe=window.frames("meizzCalendarIframe");//日历的iframe载体
93this.calendar=getObjectById("meizzCalendarLayer");//日历的层
94this.dateReg="";//日历格式验证的正则式
95this.yearFall=50;//定义年下拉框的年差值
96this.format="yyyy-mm-dd";//回传日期的格式
97this.timeShow=false;//是否返回时间
98this.drag=true;//是否允许拖动
99this.darkColor="#408080";//控件的暗色
100this.lightColor="#FFFFFF";//控件的亮色
101this.btnBgColor="#ededed";//控件的按钮背景色
102this.wordColor="#000000";//控件的文字颜色
103this.wordDark="#DCDCDC";//控件的暗文字颜色
104this.dayBgColor="#F5F5FA";//日期数字背景色
105this.todayColor="#ff3300";//今天在日历上的标示背景色
106this.DarkBorder="#D4D0C8";//日期显示的立体表达色
107}varWebCalendar=newWebCalendar();
108functioncalendar()//主调函数
109{
110vare=window.event.srcElement;
111writeIframe();
112varo=WebCalendar.calendar.style;WebCalendar.eventSrc=e;
113if(arguments.length==0)WebCalendar.objExport=e;
114elseWebCalendar.objExport=eval(arguments[0]);
115WebCalendar.iframe.tableWeek.style.cursor=WebCalendar.drag?"move":"default";
116vart=e.offsetTop,h=e.clientHeight,l=e.offsetLeft,p=e.type;
117while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值