简单的日历控件
程序员文章站
2022-04-03 09:17:39
...
//author=zheyiw //date=23/7/2009 //使用举例: onclick="ShowCalendar(InputBox,outputBox)" // InputBox是按钮控件 outputBox是日期输出的文本框 //学习用正好,要找完整的还是WalkingPoison那个版本吧。 //定义一块区域 //document.writeln("<div id='Calendar' style='position:absolute; z-index:1; visibility: hidden; filter:\"progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#999999,strength=3)\"'></div>"); document.writeln("<div id='Calendar' style='position:absolute; z-index:1; visibility: hidden; '></div>"); //document.writeln('<iframe id="Calendar" name=wpCalendarLayer frameborder=0 onmouseout="wpCalendar.correctPosition()" style="position: absolute; width: 153; height: 208; z-index: 9998; display: none"></iframe>'); //输出数据变量 var outputData; //确定日历位置,显示当前日期 function ShowCalendar(InputBox,outputBox) { outputData=outputBox; var x,y; // var o=eval("document.all."+InputBox); // var o=eval("document.getElementById(InputBox)"); //控制控件出现的位置 var o=document.getElementById(InputBox); //传入字符串时 // var o=InputBox; //传入对象时 x=o.offsetLeft; y=o.offsetTop; while(o=o.offsetParent) { x+=o.offsetLeft; y+=o.offsetTop; } document.getElementById("Calendar").style.left=x+2+"px"; document.getElementById("Calendar").style.top=y+20+"px"; document.getElementById("Calendar").style.visibility="visible"; var objdate=new Date(); MainCalendar(objdate.getYear(),objdate.getMonth(),objdate.getDate()); } //绘制日历 function MainCalendar(year,month,day) { var intLoop,intWeeks,intDays; var DivContent=""; //插入一个表格 var objdate=new Date(); var firstDay=new Date(year, month, 1).getDay(); //得到第一天是星期几 var maxday=new Date(year, month+1, 0).getDate(); //得到当前月的天数 DivContent+="<table border='0' cellspacing='0' style='border:1px solid #0066FF; background-color:#EDF2FC'>"; var strMonthMin="monthMin("+ year +","+ month +","+ day +")"; var strMonthAdd="monthAdd("+ year +","+ month +","+ day +")"; DivContent+="<tr><td align=center ><input type='button' onclick="+ strMonthAdd +" value='<'/> </td>" DivContent+="<td align=center colspan=5>"+ year +":"+ (month+1) +":"+ day +"</td>" DivContent+="<td align=center ><input type='button' onclick="+ strMonthMin +" value='>'/> </td></tr>"; DivContent+="<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td><tr>"; var d=1,dd=1; for(var i=0;i<6;i++) { DivContent+="<tr>"; var strOutData="outData(this,"+ year +","+ month +")"; for(var j=1;j<8;j++) { if(d<=firstDay || dd>maxday){DivContent+="<td> </td>";} //else if(dd==Number(objdate.getDate())) { // DivContent+="<td bgcolor='silver' onmouseover='MouseOver(this)' onmouseout='MouseOut(this)'>"+dd+"</td>"; // dd++; //} else { DivContent+="<td onmouseover='MouseOver(this)' onmouseout='MouseOut(this)' onclick="+strOutData+">"+dd+"</td>"; dd++; } d++; } DivContent+="</tr>"; } DivContent+="</table>"; //在区域中插入html document.getElementById("Calendar").innerHTML=DivContent; // newCalendar(); } //月份减少 function monthMin(year,month,day) { var DivContent=""; if (month==11) {month=0;year++;} else {month++;} document.getElementById("Calendar").innerHTML=DivContent; MainCalendar(year,month,day); } //月份增加 function monthAdd(year,month,day) { var DivContent=""; if (month==0) {month=11;year--;} else {month--;} document.getElementById("Calendar").innerHTML=DivContent; MainCalendar(year,month,day); } //鼠标经过 function MouseOver(obj) { obj.style.background="blue"; } //鼠标离开 function MouseOut(obj) { obj.style.background="#EDF2FC"; } //输出数据 function outData(obj,year,month) { var a=year+"-"+(month+1)+"-"+obj.innerText; document.getElementById(outputData).value=a; document.getElementById("Calendar").innerHTML=""; }
上一篇: linux touch命令有什么用
下一篇: Unity实现简单技能冷却管理器