欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js日历控件(可精确到分钟)

程序员文章站 2022-06-10 19:07:25
.menu_iframe{position:absolute; visibility:inherit; top:0px; left:0px; width:170px;...
" str += "" str += "" str += "" str += "" str += "" str += "
" str += "" str += "" str += "" return str; } this.play = function() { this.timer = setinterval(this.name+".playback()",1000); } this.formattime = function(stime) { stime = ("0"+stime); return stime.substr(stime.length-2); } this.playback = function() { var objdate = new date(); var arrdate = [objdate.gethours(),objdate.getminutes(),objdate.getseconds()]; var objminute = document.getelementsbyname(this.fname); for (var i=0;iradix||obj.value"; str += ""; str += ""; str += this.drawmonth(); str += ""; str += ""; str += this.drawyear(); str += ""; str += ""; str += ""; str += ""; str += "
"; str += ""; str += ""; str += ""; str += ""; str += "
"; str += this.drawdate(); str += "
"; str += ""; str += ""; str += ""; return str; } //private this.drawyear = function() { var str = ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += "
"; str += ""; //datefield str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += "
"; str += "
"; return str; } //priavate this.drawmonth = function() { //alert(this.fname); var amonthname = ["一","二","三","四","五","六","七","八","九","十","十一","十二"]; var str = ""; str += ""; return str; } //private this.drawdate = function() { var str = ""; var fday = new date(this.year,this.month,1).getday(); var fdate = 1-fday; var lday = new date(this.year,this.month+1,0).getday(); var ldate = new date(this.year,this.month+1,0).getdate(); str += ""; for (var i=1,j=fdate;i"; for (var k=0;k"+(isdate(j++))+""; } str += ""; } str += "
"; return str; function isdate(n) { return (n>=1&&nnew date(this.year,this.month+1,0).getdate()) this.date = new date(this.year,this.month+1,0).getdate(); document.getelementbyid(this.fname+"_datetable").outerhtml = this.drawdate(); //alert(this.year); //alert(this.month); //alert(this.date); getdatetime(); } //public this.getdate = function(delimiter) { var s_month,s_date; s_month=this.month+1; s_date=this.date; s_month = ("0"+s_month); s_month=s_month.substr(s_month.length-2); s_date = ("0"+s_date); s_date=s_date.substr(s_date.length-2); if (!delimiter) delimiter = "-"; var avalue = [this.year,s_month,s_date]; return avalue.join(delimiter); } } function getdatetime(){ //alert(c.getdate()+' '+m.gettime()); gdctrl.value = c.getdate()+' '+m.gettime(); } var gdctrl = new object(); function showcal(popctrl){ gdctrl = popctrl; event.cancelbubble=true; //alert(popctrl); var point = fgetxy(popctrl); //alert(point.x); //var point = new point(100,100); //alert(gdctrl.value); var gdvalue=gdctrl.value; var i_year,i_month,i_day,i_hour,i_minute; if(gdctrl.value!="" && validatedate1(gdctrl.value,'yyyy-mm-dd hh:mm')){ i_year=gdvalue.substr(0,4); if(gdvalue.substr(5,1)=="0"){ i_month=parseint(gdvalue.substr(6,1)); }else{ i_month=parseint(gdvalue.substr(5,2)); } if(gdvalue.substr(8,1)=="0"){ i_day=parseint(gdvalue.substr(9,1)); }else{ i_day=parseint(gdvalue.substr(8,2)); } i_hour1=gdvalue.substr(11,2); i_minute=gdvalue.substr(14,2); //alert(i_hour1+"aaa"); //alert(i_minute); document.getelementbyid(c.fname+"_year").value = i_year; document.getelementbyid(c.fname+"_month").value= i_month; //document.getelementbyid(c.fname+"_date").value = i_day; c.date=i_day; document.getelementsbyname(m.fname)[0].value=i_hour1; document.getelementsbyname(m.fname)[1].value=i_minute; c.redrawdate(); } //c.month= with (datetime.style) { left = point.x; top = point.y+popctrl.offsetheight+1; width = datetime.offsetwidth; height = datetime.offsetheight; //ftoggletags(point); visibility = 'visible'; } datetime.focus(); } function point(ix, iy){ this.x = ix; this.y = iy; } function validatedate1(date,format){ var time=date; if(time=="") return; var reg=format; var reg=reg.replace(/yyyy/,"[0-9]{4}"); var reg=reg.replace(/yy/,"[0-9]{2}"); var reg=reg.replace(/mm/,"((0[1-9])|1[0-2])"); var reg=reg.replace(/m/,"(([1-9])|1[0-2])"); var reg=reg.replace(/dd/,"((0[1-9])|([1-2][0-9])|30|31)"); var reg=reg.replace(/d/,"([1-9]|[1-2][0-9]|30|31))"); var reg=reg.replace(/hh/,"(([0-1][0-9])|20|21|22|23)"); var reg=reg.replace(/h/,"([0-9]|1[0-9]|20|21|22|23)"); var reg=reg.replace(/mm/,"([0-5][0-9])"); var reg=reg.replace(/m/,"([0-9]|([1-5][0-9]))"); var reg=reg.replace(/ss/,"([0-5][0-9])"); var reg=reg.replace(/s/,"([0-9]|([1-5][0-9]))"); reg=new regexp("^"+reg+"$"); if(reg.test(time)==false){//验证格式是否合法 //alert(alt); //date.focus(); return false; } return true; } function fgetxy(atag){ var otmp=atag; var pt = new point(0,0); do { pt.x += otmp.offsetleft; pt.y += otmp.offsettop; otmp = otmp.offsetparent; } while(otmp.tagname!="body"); return pt; } function hidecalendar(){ datetime.style.visibility = "hidden"; /*for (i in goselecttag) //????????,goselecttag???? goselecttag[i].style.visibility = "visible"; goselecttag.length = 0;*/ } 点击弹出时间框:
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]