相当于delphi的日历控件

2008-04-09 04:27:35来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

file://calendar.js
<!--Start-->
var YearStr,MonthStr,DayStr,NowDayStr;
var WeekStr,week,week_one;
var WeekArr = new Array("星期日", "星期一", "星期二", "星期三","星期四", "星期五", "星期六");
var dt = new Date();
var showtype;
var caleX = 0;
var caleY = 0;

YearStr = dt.getYear();
MonthStr = dt.getMonth() 1;
NowDayStr = DayStr = dt.getDate();
week = dt.getDay();
WeekStr = WeekArr[week];
document.write("<DIV id=idCalendar style=''''position:absolute;top:100px;left:100px;width:260px;border: #000000 1px solid;background-color: #ffffff;display:none''''></DIV>");

function initCalendar(){
var CaleHTML="";
CaleHTML = "<TABLE border=0 cellspacing=0 cellpadding=1 width=''''100%''''>";
CaleHTML = "<TR bgcolor=#33246C><TD><BUTTON onclick=''''prevMonth()'''' class=btn><span lang=EN-US style=''''font-family:Arial''''>&#9668;</span></BUTTON></TD>";
CaleHTML = "<TD align=center><SPAN style=''''color:white''''>" YearStr "年" MonthStr "月</SPAN></TD>"
CaleHTML = "<TD align=right><BUTTON onclick=''''nextMonth()'''' class=btn><span lang=EN-US style=''''font-family:Arial''''>&#9658;</span></BUTTON></TD></TR>";
CaleHTML = "<TR><TD colspan=3>";
CaleHTML = "<TABLE border=0 cellspacing=0 cellpadding=0 width=''''100%''''><TR>";
for(var i=0; i<WeekArr.length; i ){
CaleHTML = "<TD>" WeekArr[i] "</TD>";
}
CaleHTML = "</TR><TR><TD colspan=7><HR size=1 color=blank width=''''90%''''></TD></TR>";
CaleHTML = bodyCalendar();
CaleHTML = "</TABLE>";
CaleHTML = "</TD></TR>";
CaleHTML = "<TR><TD colspan=3>今天是:<Font color=red>" dt.getYear() "-" (dt.getMonth() 1) "-" dt.getDate() "</font></TD></TR>";
CaleHTML = "</TABLE>";
return CaleHTML;
}

function bodyCalendar(){
var ResultStr = "<TR>";
var tempStr = "" MonthStr "/1/" YearStr;
var d = new Date(tempStr);
week_one = d.getDay();
for(var i=0;i<week_one;i ){
ResultStr = "<TD></TD>";
}
var bYear = YearStr/4;
var maxDay;
switch(MonthStr){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxDay = 31;
break;
case 2:
if(bYear==0)
maxDay = 28;
else
maxDay = 29;
break;
default:
maxDay = 30;
break;
}
var k;
var bday;
for(var i=0;i<maxDay;i ){

if((i 1) == DayStr)
bday = "border: #006432 1px solid;";
file://else if((i 1) == NowDayStr)
file://bday = "border: #ff0000 1px solid;";
else
bday = "border: #ffffff 1px solid;";

BRStr = i week_one 1;
if(BRStr>=7 && BRStr%7==0){

ResultStr = "<TD align=right style=''''cursor:hand;" bday "'''' onmouseover=''''TDMove()'''' onmouseout=''''TDOut()'''' onclick=''''TDClick()''''>" eval(i 1) "</TD></TR><TR>";
k=0;
}
else{
ResultStr = "<TD align=right style=''''cursor:hand;" bday "'''' onmouseover=''''TDMove()'''' onmouseout=''''TDOut()'''' onclick=''''TDClick()''''>" eval(i 1) "</TD>";
k =1;
}
}
for(var i=0;i<7-k;i ){
ResultStr = "<TD></TD>";
}
ResultStr = "</TR>";
return ResultStr;
}

function prevMonth(){
MonthStr -= 1;
if(MonthStr == 0){
MonthStr = 12;
YearStr -= 1;
}

idCalendar.innerHTML = initCalendar();
}

function nextMonth(){
MonthStr = 1;
if(MonthStr > 12){
MonthStr = 1;
YearStr = 1;
}
idCalendar.innerHTML = initCalendar();
}


function TDMove(){
var obj = window.event.srcElement;
obj.style.setAttribute("border", "#005AB5 1px solid");
}

function TDOut(){
var obj = event.srcElement;
if(parseInt(obj.innerText) == DayStr)
obj.style.setAttribute("border","#006432 1px solid");
file://else if(parseInt(obj.innerText) == NowDayStr)
file://obj.style.setAttribute("border","#ff0000 1px solid");
else
obj.style.setAttribute("border","#ffffff 1px solid");
}
var tobj;
function showCalendar(stype){
showtype = stype;
var obj = event.srcElement;
var pobj = obj.parentElement;
tobj = pobj.childNodes(0);
v = tobj.value;
if(v != ""){
pos = v.indexOf("-");
if(pos != -1 && pos == 4){
YearStr = parseInt(v.substring(0,pos));
v = v.substring(pos 1,v.length);
}
pos = v.indexOf("-");
if(pos != -1){
MonthStr = parseInt(v.substring(0,pos));
v = v.substring(pos 1,v.length);
}
if(v.length>0)
DayStr = parseInt(v);
}
var objParent = obj.offsetParent;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:SDL Guide 中文译版(三下)

下一篇:如何使广告条自动运行,仅供学习参考