资源描述
带时间的日期控件js.docx
《带时间的日期控件js.docx》由会员分享,可在线阅读,更多相关《带时间的日期控件js.docx(27页珍藏版)》请在冰点文库上搜索。
![带时间的日期控件js.docx](https://file1.bingdoc.com/fileroot1/2023-5/6/f09b2354-53e7-457a-b3e7-866161fae739/f09b2354-53e7-457a-b3e7-866161fae7391.gif)
带时间的日期控件js
//主调用函数是setday(this,[object])和setday(this),[object]是控件输出的控件名,举两个例子:
//一、
//二、
varbMoveable=true;
varstrFrame;
document.writeln('absolute;z-index:
9998;display:
none">');
strFrame='';
strFrame+='';
strFrame+='vardatelayerx,datelayery;';
strFrame+='varbDrag;';
strFrame+='functiondocument.onmousemove()';
strFrame+='{if(bDrag&&window.event.button==1)';
strFrame+='{varDateLayer=parent.document.all.endDateLayer.style;';
strFrame+='DateLayer.posLeft+=window.event.clientX-datelayerx;';
strFrame+='DateLayer.posTop+=window.event.clientY-datelayery;}}';
strFrame+='functionDragStart()';
strFrame+='{varDateLayer=parent.document.all.endDateLayer.style;';
strFrame+='datelayerx=window.event.clientX;';
strFrame+='datelayery=window.event.clientY;';
strFrame+='bDrag=true;}';
strFrame+='functionDragEnd(){';
strFrame+='bDrag=false;}';
strFrame+='';
strFrame+='9999;position:
absolute;left:
0;top:
0;"onselectstart="returnfalse">';
strFrame+='9999;position:
absolute;top:
3;left:
19;display:
none">';
strFrame+='9999;position:
absolute;top:
3;left:
78;display:
none">';
strFrame+='9999;position:
absolute;top:
188;left:
35px;display:
none">';
strFrame+='9999;position:
absolute;top:
188;left:
77px;display:
none">';
strFrame+='9999;position:
absolute;top:
188;left:
119px;display:
none">';
strFrame+='';
strFrame+='
';strFrame+='';
strFrame+='';
strFrame+='12px;cursor:
hand;color:
#ffffff"';
strFrame+='onclick="parent.meizzPrevM()"title="向前翻1月"><';
strFrame+='12px;cursor:
hand"';
strFrame+='onmouseover="style.backgroundColor=\'#aaccf3\'"';
strFrame+='onmouseout="style.backgroundColor=\'#63A3E9\'"';
strFrame+='onclick="parent.tmpSelectYearInnerHTML(this.innerText.substring(0,4))"';
strFrame+='title="点击这里选择年份">';
strFrame+='12px;font-color:
#ffffff;cursor:
hand"';
strFrame+='bgcolor="#63A3E9"onmouseover="style.backgroundColor=\'#aaccf3\'"';
strFrame+='onmouseout="style.backgroundColor=\'#63A3E9\'"';
strFrame+='onclick="parent.tmpSelectMonthInnerHTML(this.innerText.length==3?
this.innerText.substring(0,1):
this.innerText.substring(0,2))"';
strFrame+='title="点击这里选择月份">';
strFrame+='12px;cursor:
hand;color:
#ffffff"';
strFrame+='onclick="parent.meizzNextM()"title="向后翻1月">>';
strFrame+='
';
strFrame+='';
strFrame+='
';strFrame+=''onmousedown="DragStart()"onmouseup="DragEnd()"':
'');
strFrame+='BORDERCOLORLIGHT=#63A3E9BORDERCOLORDARK=#FFFFFFwidth=140height=20style="cursor:
'+(bMoveable?
'move':
'default')+'">';
strFrame+='
12px;color:
#ffffff"width=20> 日';
strFrame+='12px;color:
#FFFFFF"> 一12px;color:
#FFFFFF"> 二';
strFrame+='12px;color:
#FFFFFF"> 三12px;color:
#FFFFFF"> 四';
strFrame+='12px;color:
#FFFFFF"> 五12px;color:
#FFFFFF"> 六
';
strFrame+='
';
strFrame+='
';strFrame+='';
varn=0;for(j=0;j<5;j++){
strFrame+='';for(i=0;i<7;i++){
strFrame+='12px"onclick=parent.meizzDayClick(this.innerText,0)>';n++;
}
strFrame+='
';
}
strFrame+='';
for(i=35;i<37;i++)strFrame+='12px"onclick="parent.meizzDayClick(this.innerText,0)">';
strFrame+='#1478eb">12px;cursor:
hand"';
strFrame+='onmouseover="style.color=\'#ff0000\'"onmouseout="style.color=\'#1478eb\'"title="将日期置空">置空 12px;cursor:
hand"';
strFrame+='onmouseover="style.color=\'#ff0000\'"onmouseout="style.color=\'#1478eb\'"title="当前日期时间">当前 hand"id=evaAllOKonmouseover="style.color=\'#ff0000\'"onmouseout="style.color=\'#1478eb\'"onclick="parent.closeLayer()"title="关闭日历">关闭 ';
strFrame+='
'; strFrame+=''; strFrame+='hand"title="点击这里启用/禁用时间"'; strFrame+='onmouseover="style.backgroundColor=\'#aaccf3\'"align=centeronmouseout="style.backgroundColor=\'#63A3E9\'"'; strFrame+='onclick="parent.UseTime(this)">'; strFrame+=' | ';strFrame+='hand"onclick="parent.tmpSelectHourInnerHTML(this.innerText.length==3?
this.innerText.substring(0,1):
this.innerText.substring(0,2))"';
strFrame+='onmouseover="style.backgroundColor=\'#aaccf3\'"onmouseout="style.backgroundColor=\'#63A3E9\'"';
strFrame+='title="点击这里选择时间"align=centerwidth=42>';
strFrame+='';
strFrame+='hand"onclick="parent.tmpSelectMinuteInnerHTML(this.innerText.length==3?
this.innerText.substring(0,1):
this.innerText.substring(0,2))"';
strFrame+='onmouseover="style.backgroundColor=\'#aaccf3\'"onmouseout="style.backgroundColor=\'#63A3E9\'"';
strFrame+='title="点击这里选择时间"align=centerwidth=42>';
strFrame+='';
strFrame+='hand"onclick="parent.tmpSelectSecondInnerHTML(this.innerText.length==3?
this.innerText.substring(0,1):
this.innerText.substring(0,2))"';
strFrame+='onmouseover="style.backgroundColor=\'#aaccf3\'"onmouseout="style.backgroundColor=\'#63A3E9\'"';
strFrame+='title="点击这里选择时间"align=centerwidth=42>';
strFrame+='';
strFrame+='
';
window.frames.endDateLayer.document.writeln(strFrame);
window.frames.endDateLayer.document.close();//解决ie进度条不结束的问题
//====================================================WEB页面显示部分======================================================
varoutObject;
varoutButton;//点击的按钮
varoutDate="";//存放对象的日期
varbUseTime=false;//是否使用时间
varodatelayer=window.frames.endDateLayer.document.all;//存放日历对象
varodatelayer=window.endDateLayer.document.all;
//odatelayer.bUseTimeLayer.innerText="NO";
bImgSwitch();
odatelayer.bUseTimeLayer.innerHTML=bImg;
functionsetday(tt,obj)//主调函数
{
if(arguments.length>2){alert("对不起!
传入本控件的参数太多!
");return;}
if(arguments.length==0){alert("对不起!
您没有传回本控件任何参数!
");return;}
vardads=document.all.endDateLayer.style;
varth=tt;
varttop=tt.offsetTop;//TT控件的定位点高
varthei=tt.clientHeight;//TT控件本身的高
vartleft=tt.offsetLeft;//TT控件的定位点宽
varttyp=tt.type;//TT控件的类型
while(tt=tt.offsetParent){ttop+=tt.offsetTop;tleft+=tt.offsetLeft;}
dads.top=(ttyp=="image")?
ttop+thei:
ttop+thei+6;
dads.left=tleft;
outObject=(arguments.length==1)?
th:
obj;
outButton=(arguments.length==1)?
null:
th;//设定外部点击的按钮
//根据当前输入框的日期显示日历的年月
varreg=/^(\d+)-(\d{1,2})-(\d{1,2})/;//不含时间
varr=outObject.value.match(reg);
if(r!
=null){
r[2]=r[2]-1;
vard=newDate(r[1],r[2],r[3]);
if(d.getFullYear()==r[1]&&d.getMonth()==r[2]&&d.getDate()==r[3]){
outDate=d;
parent.meizzTheYear=r[1];
parent.meizzTheMonth=r[2];
parent.meizzTheDate=r[3];
}
else{
outDate="";
}
meizzSetDay(r[1],r[2]+1);
}
else{
outDate="";
meizzSetDay(newDate().getFullYear(),newDate().getMonth()+1);
}
dads.display='';
//判断初始化时是否使用时间,非严格验证
//if(outObject.value.length>10)
//{
bUseTime=true;
bImgSwitch();
odatelayer.bUseTimeLayer.innerHTML=bImg;
meizzWriteHead(meizzTheYear,meizzTheMonth);
//}
//else
//{
//bUseTime=false;
//bImgSwitch();
//odatelayer.bUseTimeLayer.innerHTML=bImg;
//meizzWriteHead(meizzTheYear,meizzTheMonth);
//}
try{
event.returnValue=false;
}
catch(e){
//此处排除错误,错误原因暂未找到。
}
}
varMonHead=newArray(12);//定义阳历中每个月的最大天数
MonHead[0]=31;MonHead[1]=28;MonHead[2]=31;MonHead[3]=30;MonHead[4]