源码学习:一个简单的日历控件
btnCell.onmouseover=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:#F0F0F0;"; 织梦内容管理系统
}
btnCell.onmouseout=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:buttonface;";
}
// btnCell.onmousedown=function(){
// btnCell.style.cssText="width:100%;border:1 inset;background-color:#F0F0F0;";
// }
btnCell.onmouseup=function(){
btnCell.style.cssText="width:100%;border:1 outset;background-color:#F0F0F0;";
}
btnCell.onclick=function(){
btnCell.blur();
}
return btnCell;
}
this.setDefaultDate=function(){
var dftDate=new Date();
calendar.today[0]=dftDate.getYear();
calendar.today[1]=dftDate.getMonth() 1;
calendar.today[2]=dftDate.getDate();
} 织梦内容管理系统
/****************** Show Calendar *********************/
this.show=function(targetObject,defaultDate,sourceObject){
if(targetObject==undefined) {
alert("未设置目标对像. 方法: ATCALENDAR.show(obj 目标对像,string 默认日期,obj 点击对像);目标对像:接受日期返回值的对像.默认日期:格式为\"yyyy-mm-dd\",缺省为当日日期.点击对像:点击这个对像弹出calendar,默认为目标对像.");
return false;
}
else calendar.target=targetObject;
if(sourceObject==undefined) calendar.source=calendar.target;
else calendar.source=sourceObject; 织梦好,好织梦
var firstDay;
var Cells=new Array();
织梦好,好织梦
if(defaultDate==undefined || defaultDate==""){
var theDate=new Array();
calendar.head.innerText = calendar.today[0] "-" calendar.today[1] "-" calendar.today[2];
theDate[0]=calendar.today[0]; theDate[1]=calendar.today[1]; theDate[2]=calendar.today[2];
}
else{
var reg=/^\d{4}-\d{1,2}-\d{2}$/
if(!defaultDate.match(reg)){
alert("默认日期的格式不正确默认日期可接受格式为:'yyyy-mm-dd'");
return;
}
var theDate=defaultDate.split("-");
calendar.head.innerText = defaultDate;
}
calendar.currentDate[0]=theDate[0];
calendar.currentDate[1]=theDate[1];
calendar.currentDate[2]=theDate[2];
theFirstDay=calendar.getFirstDay(theDate[0],theDate[1]);
theMonthLen=theFirstDay calendar.getMonthLen(theDate[0],theDate[1]);
file://calendar.setEventKey();
本文来自织梦
calendar.calendarPad.style.display="";
var theRows = Math.ceil((theMonthLen)/7);
file://清除旧的日历;
while (calendar.body.rows.length > 0) {
calendar.body.deleteRow(0)
}
file://建立新的日历;
var n=0;day=0;
for(i=0;i<theRows;i ){
theRow=calendar.body.insertRow(i);
for(j=0;j<7;j ){
n ;
if(n>theFirstDay && n<=theMonthLen){
day=n-theFirstDay;
calendar.insertBodyCell(theRow,j,day);
} 内容来自dedecms
else{
var theCell=theRow.insertCell(j);
theCell.style.cssText="background-color:#F0F0F0;cursor:default;";
}
}
} dedecms.com
file://****************调整日历位置**************//
var offsetPos=calendar.getAbsolutePos(calendar.source);//计算对像的位置;
文章评论
共有位Admini5网友发表了评论 查看完整内容