📄 datetag.js
字号:
var dt=new Date(year,month-1,day).getDay()/7; return dt;
}
function meizzPrevY() //往前翻 Year
{
if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}
else{alert("年份超出范围(1000-9999)!");}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzNextY() //往后翻 Year
{
if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}
else{alert("年份超出范围(1000-9999)!");}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzToday() //Today Button
{
var today;
meizzTheYear = new Date().getFullYear();
meizzTheMonth = new Date().getMonth()+1;
today=new Date().getDate();
//meizzSetDay(meizzTheYear,meizzTheMonth);
var mm = meizzTheMonth;
var dd = today;
if (mm<10) mm="0"+mm;
if (dd<10)dd="0"+dd;
if(outObject){
setDateTagValue(meizzTheYear + "-" + mm + "-" + dd);
}
closeLayer();
}
function meizzPrevM() //往前翻月份
{
if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzNextM() //往后翻月份
{
if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzSetDay(yy,mm) //主要的写程序**********
{
meizzWriteHead(yy,mm);
//设置当前年月的公共变量为传入值
meizzTheYear=yy;
meizzTheMonth=mm;
for (var i = 0; i < 42; i++){meizzWDay[i]=""}; //将显示框的内容全部清空
var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几
for (i=0;i<firstday;i++)meizzWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1 //上个月的最后几天
for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){meizzWDay[i]=day1;day1++;}
for (i=firstday+GetMonthCount(yy,mm);i<42;i++){meizzWDay[i]=day2;day2++}
for (i = 0; i < 42; i++)
{ var da = eval("odatelayer.meizzDay"+i) //书写新的一个月的日期星期排列
if (meizzWDay[i]!="")
{
//初始化边框
da.borderColorLight="#FFFFFF";//"#9496E1";
da.borderColorDark="#FFFFFF";
if(i<firstday) //上个月的部分
{
da.innerHTML="<b><font color=gray>" + meizzWDay[i] + "</font></b>";
da.title=(mm==1?12:mm-1) +"月" + meizzWDay[i] + "日";
da.onclick=Function("meizzDayClick(this.innerText,-1)");
if(!outDate)
da.style.backgroundColor = ((mm==1?yy-1:yy) == new Date().getFullYear() &&
(mm==1?12:mm-1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
"#0053EC":"#FFFFFF";
else
{
da.style.backgroundColor =((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 &&
meizzWDay[i]==outDate.getDate())? "#0053EC" :
(((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 &&
meizzWDay[i] == new Date().getDate()) ? "#0053EC":"#FFFFFF");
//将选中的日期显示为凹下去
if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 &&
meizzWDay[i]==outDate.getDate())
{
da.borderColorLight="#FFFFFF";
da.borderColorDark="#9496E1";
}
}
}
else if (i>=firstday+GetMonthCount(yy,mm)) //下个月的部分
{
da.innerHTML="<b><font color=gray>" + meizzWDay[i] + "</font></b>";
da.title=(mm==12?1:mm+1) +"月" + meizzWDay[i] + "日";
da.onclick=Function("meizzDayClick(this.innerText,1)");
da.style.borderLeft="0px solid #8EA525";
da.style.borderTop="0px solid #8EA525";
if(!outDate)
da.style.backgroundColor = ((mm==12?yy+1:yy) == new Date().getFullYear() &&
(mm==12?1:mm+1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
"#0053EC":"#FFFFFF";
else
{
da.style.backgroundColor =((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 &&
meizzWDay[i]==outDate.getDate())? "#0053EC" :
(((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 &&
meizzWDay[i] == new Date().getDate()) ? "#0053EC":"#FFFFFF");
//将选中的日期显示为凹下去
if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 &&
meizzWDay[i]==outDate.getDate())
{
da.borderColorLight="#FFFFFF";
da.borderColorDark="#9496E1";
}
}
}
else //本月的部分
{
var commomn_bgColor = "#FFFFFF";
da.innerHTML="<b>" + meizzWDay[i] + "</b>";
da.title=mm +"月" + meizzWDay[i] + "日";
da.onclick=Function("meizzDayClick(this.innerText,0)"); //给td赋予onclick事件的处理
//如果是当前选择的日期,则显示暗黄色的背景;如果是当前日期,则显示亮紫色的背景
if(!outDate)
da.style.backgroundColor = (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
"#0053EC":"#FFFFFF";
else
{
da.style.backgroundColor =(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())?
"#0053EC":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
"#FFFFFF":commomn_bgColor);//"#E0E0E0");
if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate() )
{
da.style.color = "#FFFFFF";
}else
da.style.color = "black";
//将选中的日期显示为凹下去
if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())
{
da.borderColorLight="#FFFFFF";
da.borderColorDark="#9496E1";
}
}
}
da.style.cursor="hand"
}
else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}
}
}
function meizzDayClick(n,ex) //点击显示框选取日期,主输入函数*************
{
var yy=meizzTheYear;
var mm = parseInt(meizzTheMonth)+ex; //ex表示偏移量,用于选择上个月份和下个月份的日期
//判断月份,并进行对应的处理
if(mm<1){
yy--;
mm=12+mm;
}
else if(mm>12){
yy++;
mm=mm-12;
}
if (mm < 10){mm = "0" + mm;}
if (outObject)
{
if (!n) {//outObject.value="";
return;}
if ( n < 10){n = "0" + n;}
setDateTagValue(yy + "-" + mm + "-" + n ); //注:在这里你可以输出改成你想要的格式
closeLayer();
}
else {closeLayer(); alert("您所要输出的控件对象并不存在!");}
}
function setDateTagValue(val){
var oldValue = outObject.value;
outObject.value= val;
if(oldValue != outObject.value){
outObject.fireEvent("onChange");
}
}
function getTodayStr()
{
var today;
meizzTheYear = new Date().getFullYear();
meizzTheMonth = new Date().getMonth()+1;
today=new Date().getDate();
//meizzSetDay(meizzTheYear,meizzTheMonth);
var mm = meizzTheMonth;
var dd = today;
if (mm<10) mm="0"+mm;
if (dd<10)dd="0"+dd;
return meizzTheYear + "-" + mm + "-" + dd;
}
//2006.3.13 格式化日期输入
function adjustDateFormat(obj)
{
if( !obj || !obj.value || obj.value.length <=0 ) return;
with(obj)
{
var reg1 = /^(\d{1,4})(\d{2})(\d{2})$/;
if( reg1.test( value ) )
{
reg1.exec(value);
var y = Number(RegExp.$1 ) ;
var y = Number(RegExp.$1);
if( y < 100 )
{
if( y >= 50 )
y = '19' + RegExp.$1;
else
{
if( y >= 10 )
y = '20' + String( y );
else
y = '200' + String( y );
}
}
value = y + '-' + RegExp.$2 +'-'+RegExp.$3;
return;
}
var reg2 = /^(\d{1,4})[\D]+(\d{1,2})[\D]+(\d{1,2})$/;
if( reg2.test( value ) ){
reg2.exec(value);
var y = Number(RegExp.$1);
if( y < 100 )
{
if( y >= 50 )
y = '19' + RegExp.$1;
else
{
if( y >= 10 )
y = '20' + String( y );
else
y = '200' + String( y );
}
}
var m = Number(RegExp.$2);
if( m < 10 )
m = '0' + String( m );
var d = Number(RegExp.$3);
if( d < 10 )
d = '0' + String( d );
value = y+'-'+m+'-'+d;
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -