日历控件(四)

thfwin 2011-08-30 05:32:07

function nextMi() // 往后翻小时

{

WebCalendar.thisMinute++;

if(WebCalendar.thisMinute==60)

{

WebCalendar.thisMinute=0;

}

writeCalendar();

}

function prevY(){WebCalendar.thisDay = 1; WebCalendar.thisYear--; writeCalendar();}// 往前翻
// Year

function nextY(){WebCalendar.thisDay = 1; WebCalendar.thisYear++; writeCalendar();}// 往后翻
// Year

function hiddenSelect(e){for(var i=e.options.length; i>-1; i--)e.options.remove(i); e.style.display="none";}

function getObjectById(id){ if(document.all) return(eval("document.all."+ id)); return(eval(id)); }

function hiddenCalendar(){getObjectById("meizzCalendarLayer").style.display = "none";};

function appendZero(n){return(("00"+ n).substr(("00"+ n).length-2));}// 日期自动补零程序

function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
// function trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}

function dayMouseOver()

{

this.className = "over";

this.style.backgroundColor = WebCalendar.darkColor;

if(WebCalendar.day[this.id.substr(8)].split("/")[1] == WebCalendar.thisMonth)

this.style.color = WebCalendar.lightColor;

}

function dayMouseOut()

{

this.className = "out"; var d = WebCalendar.day[this.id.substr(8)], a = d.split("/");

this.style.removeAttribute('backgroundColor');

if(a[1] == WebCalendar.thisMonth && d != WebCalendar.today)

{

if(WebCalendar.dateStyle && a[0] == parseInt(WebCalendar.dateStyle[4], 10))

this.style.color = WebCalendar.lightColor;

this.style.color = WebCalendar.wordColor;

}

}

function writeCalendar() // 对日历显示的数据的处理程序

{

var y = WebCalendar.thisYear;

var m = WebCalendar.thisMonth;

var d = WebCalendar.thisDay;

var h = WebCalendar.thisHour;

var mi = WebCalendar.thisMinute;

var s = WebCalendar.thisSecond;

WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28;

if (!(y<=9999 && y >= 1000 && parseInt(m, 10)>0 && parseInt(m, 10)<13 && parseInt(d, 10)>0)){

alert("对不起,你输入了错误的日期!");

WebCalendar.thisYear = new Date().getFullYear();

WebCalendar.thisMonth = new Date().getMonth()+ 1;

WebCalendar.thisDay = new Date().getDate();

WebCalendar.thisHour = new Date().getHours();

WebCalendar.thisMinute = new Date().getMinutes();

WebCalendar.thisSecond = new Date().getSeconds();

}

y = WebCalendar.thisYear;

m = WebCalendar.thisMonth;

d = WebCalendar.thisDay;

h = WebCalendar.thisHour;

mi = WebCalendar.thisMinute;

s = WebCalendar.thisSecond;

WebCalendar.iframe.meizzYearHead.innerText = y +" 年";

WebCalendar.iframe.meizzYearMonth.innerText = parseInt(m, 10) +" 月";

WebCalendar.iframe.meizzHourHead.innerText =appendZero(parseInt(h, 10)) +" 时";

WebCalendar.iframe.meizzMinuteHead.innerText =appendZero(parseInt(mi, 10)) +" 分";

WebCalendar.iframe.meizzSecondHead.innerText =appendZero(parseInt(s, 10))+" 秒";

WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28; // 闰年二月为29天

var w = new Date(y, m-1, 1).getDay();

var prevDays = m==1 ? WebCalendar.daysMonth[11] : WebCalendar.daysMonth[m-2];

for(var i=(w-1); i>=0; i--) // 这三个 for 循环为日历赋数据源(数组 WebCalendar.day)格式是
// d/m/yyyy

{

WebCalendar.day[i] = prevDays +"/"+ (parseInt(m, 10)-1) +"/"+ y;

if(m==1) WebCalendar.day[i] = prevDays +"/"+ 12 +"/"+ (parseInt(y, 10)-1);

prevDays--;

}

for(var i=1; i<=WebCalendar.daysMonth[m-1]; i++) WebCalendar.day[i+w-1] = i +"/"+ m +"/"+ y;

for(var i=1; i<39-w-WebCalendar.daysMonth[m-1]+1; i++)

{

WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ (parseInt(m, 10)+1) +"/"+ y;

if(m==12) WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ 1 +"/"+ (parseInt(y, 10)+1);

}

for(var i=0; i<39; i++) // 这个循环是根据源数组写到日历里显示

{

var a = WebCalendar.day[i].split("/");

WebCalendar.dayObj[i].innerText = a[0];

WebCalendar.dayObj[i].title = a[2] +"-"+ appendZero(a[1]) +"-"+ appendZero(a[0]);

WebCalendar.dayObj[i].bgColor = WebCalendar.dayBgColor;

WebCalendar.dayObj[i].style.color = WebCalendar.wordColor;

if ((i<10 && parseInt(WebCalendar.day[i], 10)>20) || (i>27 && parseInt(WebCalendar.day[i], 10)<12))

WebCalendar.dayObj[i].style.color = WebCalendar.wordDark;

if (WebCalendar.inputDate==WebCalendar.day[i]) // 设置输入框里的日期在日历上的颜色

{WebCalendar.dayObj[i].bgColor = WebCalendar.darkColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}

if (WebCalendar.day[i] == WebCalendar.today) // 设置今天在日历上反应出来的颜色

{WebCalendar.dayObj[i].bgColor = WebCalendar.todayColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}

}

}

function returnDate() // 根据日期格式等返回用户选定的日期

{

if(WebCalendar.objExport)

{

var returnValue;

var a = (arguments.length==0) ? WebCalendar.day[this.id.substr(8)].split("/") : arguments[0].split("/");

var d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2})$/);

if(d==null){alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !"); return false;}

var flag = d[3].length==2 || d[4].length==2; // 判断返回的日期格式是否要补零

returnValue = flag ? a[2] +d[2]+ appendZero(a[1]) +d[2]+ appendZero(a[0]) : a[2] +d[2]+ a[1] +d[2]+ a[0];

if(WebCalendar.timeShow)

{

var h = WebCalendar.thisHour, m = WebCalendar.thisMinute, s = WebCalendar.thisSecond;

returnValue += flag ? " "+ appendZero(h) +":"+ appendZero(m) +":"+ appendZero(s) : " "+ h +":"+ m +":"+ s;

}

WebCalendar.objExport.value = returnValue;

hiddenCalendar();

}

}
...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
打字员 2011-08-31
  • 打赏
  • 举报
回复
是在测试发帖吗?
lsw645645645 2011-08-30
  • 打赏
  • 举报
回复

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧