📄 ye_datetime.js
字号:
//Maker nichoals!
<!--
//drag the layer when mouse on or over
var drag = 0;
var move = 0;
var flag=1;
function init() {
window.document.onmousemove = mouseMove
window.document.onmousedown = mouseDown
window.document.onmouseup = mouseUp
window.document.ondragstart = mouseStop
}
function mouseDown() {
if (drag) {
clickleft = window.event.x - parseInt(dragObj.style.left)
clicktop = window.event.y - parseInt(dragObj.style.top)
dragObj.style.zIndex += 1
move = 1
}
}
function mouseStop() {
window.event.returnValue = false
}
function mouseMove() {
if (move) {
dragObj.style.left = window.event.x - clickleft
dragObj.style.top = window.event.y - clicktop
}
}
function mouseUp() {
move = 0
}
function showCal(obj){
var nowd=now.getDate();
var nowm=now.getMonth();
var nowy=now.getYear();
showCalendar(nowd,nowm,nowy,1,obj);init();
if(flag==1)
{
var ttop = obj.offsetTop;
var thei = obj.clientHeight;
var tleft = obj.offsetLeft;
var ttyp = obj.type;
var i=0;
while (obj = obj.offsetParent)
{
ttop+=obj.offsetTop;
tleft+=obj.offsetLeft;
}
document.all.calendar.style.top=(ttyp=="image")? ttop+thei : ttop+thei+6;
document.all.calendar.style.left=tleft;
document.all.calendar.style.visibility="visible";
flag=0;
}else{
flag=1;
document.all.calendar.style.visibility="hidden";
}
}
function setDate(cDate,obj)
{
eval("document.all."+obj).value=cDate;
flag=1;
document.all.calendar.style.visibility="hidden";
}
var dayName=new Array("S","M","T","W","T","F","S")
var monthName=new Array("1","2","3","4","5","6","7", "8","9","10","11","12")
var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
var now=new Date
var nowd=now.getDate()
var nowm=now.getMonth()
var nowy=now.getYear()
var sign
var colorClass
function showCalendar(day,month,year,i,obj)
{
if (day != null || month != null || year != null){
nowd=day;
nowm=month;
nowy=year;
sign=i;
ooBj=obj
switch (nowm){
case -1:
{ nowy--; year--; nowm=11; month=11;}
break;
case 12:
{ nowy++; nowm=0;year++;month=0;}
}
}
if ((year%4==0||year%100==0)&&(year%400==0)) monthDays[1]=29; else monthDays[1]=28 //leap year test
var firstDay=new Date(year,month,1).getDay()
var calStr="<table border=0 cellpadding=0 cellspacing=1 bgcolor=#333333><tr><td><table width=100% border=0 cellpadding=0 cellspacing=1 bgcolor=#EDEDE1>"
calStr+="<TR bgcolor=#E3E2C3>"
calStr+="<TD colspan=2> <a href=# onClick='nowy-=20;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'><</a> <a href=# onClick='nowy--;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'><</a> <a href=# onClick='nowm--;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'><</a> </td>"
calStr+="<TD COLSPAN=3 ALIGN=center >"+year+"-"+monthName[month].toUpperCase()+"</td>"
calStr+="<TD colspan=2 ALIGN=right> <a href=# onClick='nowm++;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'>></a> <a href=# onClick='nowy++;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'>></a> <a href=# onClick='nowy+=20;showCalendar(nowd,nowm,nowy,sign,ooBj);return false;'>></a> </td></tr>"
calStr+="<TR bgcolor=#EDEDE1>"
for (var i=0;i<dayName.length;i++) calStr+="<TD ALIGN=center class=cal_week>"+dayName[i].substring(0,1)
var dayCount=1
calStr+="</td></tr>"
calStr+="<tr bgcolor=#ffffff><td HEIGHT=1 ALIGN=MIDDLE COLSPAN=7><img SRC=img/line.gif HEIGHT=1 WIDTH=140 BORDER=0></td></tr>"
for (var i=0;i<firstDay;i++) calStr+="<TD bgcolor=#ffffff> "
for (var i=0;i<monthDays[month];i++)
{
if(dayCount==nowd&&month==now.getMonth())
colorClass=" style='color:#ff4500;' "
else
colorClass=""
calStr+="<TD class=date ALIGN=center bgcolor=#ffffff><a "+colorClass+" href=javascript:setDate('"+year+"-"+(month+1)+"-"+dayCount+"','"+obj.name+"')>"+dayCount++
if ((i+firstDay+1)%7==0&&(dayCount<monthDays[month]+1)) calStr+="</A></TD></tr><TR>"
}
var totCells=firstDay+monthDays[month]
for (var i=0;i<(totCells>28?(totCells>35?42:35):28)-totCells;i++) calStr+="<TD bgcolor=#ffffff> "
calStr+="</tr></TABLE></td></tr></TABLE><BR>"
calendar.innerHTML=calStr
}
//成生日期显示层
document.write("<div id='calendar' style='LEFT: 480px; WIDTH: 90px; CURSOR: move; POSITION: absolute; TOP: 90px; HEIGHT: 90px' align='center' onmouseover='dragObj=calendar; drag=1;' onmouseout='drag=0'><\/div>");
//-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -