相當於delphi的日曆控制元件 (轉)

worldblog發表於2007-12-15
相當於delphi的日曆控制元件 (轉)[@more@]


<!--Start--&gt
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("

");

function initCalendar(){
 var CaleHTML="";
 CaleHTML += "

";
 CaleHTML += "";
 CaleHTML += ""
 CaleHTML += "";
 CaleHTML += "";
 CaleHTML += "";
 CaleHTML += "
"+ YearStr +"年"+ MonthStr +"月
";
 CaleHTML += "";
 for(var i=0; i CaleHTML += "";
 }
 CaleHTML += "";
 CaleHTML += bodyCalendar();
 CaleHTML += "
" + WeekArr[i] + "

";
 CaleHTML += "
今天是:"+ dt.getYear() +"-"+ (dt.getMonth() + 1) +"-"+ dt.getDate() +"
";
 return CaleHTML;
}

function bodyCalendar(){
 var ResultStr = "

";
 var tempStr = "" + MonthStr + "/1/" + YearStr;
 var d = new Date(tempStr);
 week_one = d.getDay();
 for(var i=0;i ResultStr += "";
 }
 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

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

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

 ResultStr += "

"+ eval(i+1) +"
";
 k=0;
 }
 else{
 ResultStr += ""+ eval(i+1) +"";
 k+=1;
 }
 }
 for(var i=0;i<7-k;i++){
 ResultStr += "";
 }
 ResultStr += "";
 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");
  if(parseInt(obj.innerText) == NowDayStr)
 ("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 != ""){
 p= 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;
 var left  = obj.offsetLeft;
 var top  = obj.offsetTop;
 while(objParent.tagName.toUpperCase() != "BODY"){
 left += objParent.offsetLeft;
 top  += objParent.offsetTop;
 objParent = objParent.offsetParent;
 }
 left += obj.offsetWidth;
 top  += obj.offsetHeight;

 idCalendar.style.top = top+1;
 idCalendar.style.left = left-260;
 caleX = left - 260;
 caleY = top + 1;
 idCalendar.innerHTML = initCalendar();
 idCalendar.style.display="";
 hElement("");
 /*var left = event.clientX;
 var top  = event.clientY;
 idCalendar.style.top = top+5;
 idCalendar.style.left = left-250;
 idCalendar.innerHTML = initCalendar();
 idCalendar.style.display="";*/
}

function TDClick(){
 DayStr = event.srcElement.innerText;
 if(showtype=="day"){
 tobj.value = YearStr + "-" + MonthStr + "-" + DayStr;
 }
 else{
 tobj.value = YearStr + "-" + MonthStr;
 }
 hideCalendar();
}

function getCaleToSec(){
 var dt;
 if(showtype=="day")
 dt = new Date(MonthStr+"/"+DayStr+"/"+YearStr);
 else
 dt = new Date(MonthStr+"/1/"+YearStr);
 var s  = dt.getTime();
 return s/1000;
}

function hideCalendar(){
 idCalendar.style.display = "none";
 showElement("SELECT");
}

function C_MouseUp(){
 if(idCalendar == null)
 return;
 var top  = parseInt(idCalendar.style.top);
 var left = parseInt(idCalendar.style.left);
 var wi  = idCalendar.offsetWidth;
 var he  = idCalendar.offsetHeight;
 var x  = event.clientX;
 var y  = event.clientY;
 var x1 = left + wi;
 var y1 = top + he;

 if(x>x1||xy1||y hideCalendar();
 showElement("SELECT");
 }
}

function hideElement(elmID){
 for (i = 0; i < document.all.tags(elmID).length; i++){
 obj = document.all.tags(elmID)[i];
 if (! obj || ! obj.offsetParent)
 continue;

 objLeft  = obj.offsetLeft;
 objTop  = obj.offsetTop;
 objParent = obj.offsetParent;
 while (objParent.tagName.toUpperCase() != "BODY")
 {
 objLeft  += objParent.offsetLeft;
 objTop  += objParent.offsetTop;
 objParent = objParent.offsetParent;
 }

 if(caleX > (objLeft + obj.offsetWidth) || objLeft > (caleX + idCalendar.offsetWidth))
 ;
 else if(objTop > (caleY + idCalendar.offsetHeight))
 ;
 else if(caleY > (objTop + obj.offsetHeight))
 ;
 else
 obj.style.visibility = "hidden";
 }
}

function showElement(elmID){
 for (i = 0; i < document.all.tags(elmID).length; i++){
 obj = document.all.tags(elmID)[i];
 if (! obj || ! obj.offsetParent)
 continue;
 obj.style.visibility = "";
 }
}

document.onmouseup = C_MouseUp;
<!--End--&gt
//DTD HTML 4.0 Transitional//EN">

日曆測試 words" CONTENT="">'>file://TestCale.html



日曆測試







 





 
 
 

 
 
 
 




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993850/,如需轉載,請註明出處,否則將追究法律責任。

相關文章