ASP+javascript的完整的日历使用

2013 年 8 月 12 日4510

  第一步:保存下列文件为:CALENDAR.ASP "" then sOutputStr = sOutputStr & " FACE='" & sFace & "'" else sOutputStr = sOutputStr & " FACE='Helv'" end if if iSize = "" then iSize = 1 end if if bScale then iSize = cInt(iSize * 1) end if sOutputStr = sOutputStr & " SIZE=" & iSize if sColor "" then sOutputStr = sOutputStr & " COLOR=" & sColor end if sOutputStr = sOutputStr & ">" sFont = sOutputStrEnd FunctionOn Error Resume Next Dim datecntrl, Dy, Mo, Yr, nextmonth, startwith, thisMo, thisYr, thisDate,the_typeDim prevMonthLastDate, currMonthLastDate, i, j, lastnum, AnyDate,default_valuedatecntrl= Request("object")default_value=request("value")the_type=request("type")if the_type"datetime" then the_type="date"end ifif default_value="" then Yr = year(date) Mo = month(date) Dy = day(date)else dim pos1 dim deal_value deal_value=default_value pos1=instr(deal_value,"-") Yr = cint(mid(deal_value,1,pos1-1)) deal_value=mid(deal_value,pos1+1) pos1=instr(deal_value,"-") Mo = cint(mid(deal_value,1,pos1-1)) if trim(the_type)="date" then Dy = cint(mid(deal_value,pos1+1)) else dim H,M,S deal_value=mid(deal_value,pos1+1) pos1=instr(deal_value," ") Dy=cint(mid(deal_value,1,pos1-1)) deal_value=mid(deal_value,pos1+1) pos1=instr(deal_value,":") H=cint(mid(deal_value,1,pos1-1)) deal_value=mid(deal_value,pos1+1) pos1=instr(deal_value,":") M=cint(mid(deal_value,1,pos1-1)) S=cint(mid(deal_value,pos1+1)) end if end ifnextmonth = false%> FrontPage 4.0"> FrontPage.Editor.Document"> A { FONT-SIZE: 13px; COLOR: #000000;TEXT-DECORATION: none } A:hover {COLOR: #ff0000; } 日历 //检查字符串是否为日期,返回值:false、truefunction f_chkDate(datestr){ var lthdatestr if (datestr != "") lthdatestr= datestr.length ; else lthdatestr=0; var tmpy=""; var tmpm=""; var tmpd=""; //var datestr; var status; status=0; if ( lthdatestr== 0) return false; if(lthdatestr>10) return false; for (i=0;i 2) { //alert("Invalid format of date!"); return false; } if ((status==0) && (datestr.charAt(i)!='-')) { tmpy=tmpy+datestr.charAt(i) } if ((status==1) && (datestr.charAt(i)!='-')) { tmpm=tmpm+datestr.charAt(i) } if ((status==2) && (datestr.charAt(i)!='-')) { tmpd=tmpd+datestr.charAt(i) } } year=new String (tmpy); month=new String (tmpm); day=new String (tmpd); //tempdate= new String (year+month+day); //alert(tempdate); if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2)) { //alert("Invalid format of date!"); return false; } if (!((1=month) && (31>=day) && (1=31)) { //alert ("This month is a small month!"); return false; } if ((month>=8) && ((month % 2)==1) && (day>=31)) { //alert ("This month is a small month!"); return false; } if ((month==2) && (day==30)) { //alert("The Febryary never has this day!"); return false; } return true;} function right(str,number) { return str.substr(str.length - number,str.length); } function setDate(Dy,Mo,Yr,VBool) { if (vBool) { if (Mo top.opener..value =Yr+"-"+Mo+"-"+Dy+" "+userform.hour.value+":"+userform.minute.value+":"+userform.second.value; top.opener..value =Yr+"-"+Mo+"-"+Dy; top.window.close(); } self.location.href="calendar.asp?type= self.location.href="calendar.asp?type= } function saveDate() { top.opener..value =""+" "+userform.hour.value+":"+userform.minute.value+":"+userform.second.value; top.opener..value =""; top.window.close(); } maxdays then startwith = 1 end if nextDate = startwith end function function GetLastDay(Mo,Yr) if Mo=2 then if (Yr Mod 4)=0 then GetLastDay = 29 else GetLastDay = 28 end if elseif ((Mo = 0) OR (Mo = 1) OR (Mo = 3) OR (Mo = 5) OR (Mo = 7) OR (Mo = 8) OR (Mo = 10) OR (Mo = 12)) then GetLastDay = 31 else GetLastDay = 30 end if end function function GetFirstDayOffset(Mo,Yr) GetFirstDayOffset = weekday(Mo & "/01/" & Yr)-1 end function function writeMonths(selMo) dim i, selstr selstr = "" for i=1 to 12 if selMo = i then selstr = selstr & "" & MonthName(i) else selstr = selstr & "" & MonthName(i) end if next selstr = selstr & "" writeMonths = selstr end function function writeYears(selYear) dim i, selstr selstr = "" for i=1900 to 2100 if selYear = i then selstr = selstr & "" & i & "年" else selstr = selstr & "" & i & "年" end if next selstr = selstr & "" writeYears = selstr end function prevMonthLastDate=GetLastDay((Mo-1),Yr) currMonthLastDate=GetLastDay(Mo,Yr) startwith=(prevMonthLastDate-GetFirstDayOffset(Mo, Yr))%> 日 一 二 三 四 五 六 , ,,false);" > startwith then%> , , ,false);" > "+right("0"+cstr(i),2)+"时"+"" else response.write ""+right("0"+cstr(i),2)+"时"+"" end if next %> "+right("0"+cstr(i),2)+"分"+"" else response.write ""+right("0"+cstr(i),2)+"分"+"" end if next %> "+right("0"+cstr(i),2)+"秒"+"" else response.write ""+right("0"+cstr(i),2)+"秒"+"" end if next %> var strDate = +"-"+right(("0"+),2)+"-"+right(("0"+),2);if (f_chkDate(strDate)) document.all.ok.disabled = false;else document.all.ok.disabled = true; 第二步:保存下列文件为:&106avascriptdate.jsfunction f_get_date(object_name){ var object_value=""; eval("object_value="+object_name+".value");if(!f_chkDate(object_value)){ var v_today=new Date(); object_value=v_today.getYear()+"-"+(v_today.getMonth()+1)+"-"+(v_today.getDate()); }open('calendar.asp?type=date}//获取日历时间函数function f_get_datetime(object_name){ var object_value=""; eval("object_value="+object_name+".value"); open('calendar.asp?type=datetime}//检查字符串是否为日期,返回值:false、truefunction f_chkDate(datestr){ var lthdatestr if (datestr != "") lthdatestr= datestr.length ; else lthdatestr=0; var tmpy=""; var tmpm=""; var tmpd=""; //var datestr; var status; status=0; if ( lthdatestr== 0) return false; if(lthdatestr>10) return false; for (i=0;i 2) { //alert("Invalid format of date!"); return false; } if ((status==0) && (datestr.charAt(i)!='-')) { tmpy=tmpy+datestr.charAt(i) } if ((status==1) && (datestr.charAt(i)!='-')) { tmpm=tmpm+datestr.charAt(i) } if ((status==2) && (datestr.charAt(i)!='-')) { tmpd=tmpd+datestr.charAt(i) } } year=new String (tmpy); month=new String (tmpm); day=new String (tmpd); //tempdate= new String (year+month+day); //alert(tempdate); if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2)) { //alert("Invalid format of date!"); return false; } if (!((1=month) && (31>=day) && (1=31)) { //alert ("This month is a small month!"); return false; } if ((month>=8) && ((month % 2)==1) && (day>=31)) { //alert ("This month is a small month!"); return false; } if ((month==2) && (day==30)) { //alert("The Febryary never has this day!"); return false; } return true;}第三步:在页中加入如下示例:(使用页) 1.获取日期: f_get_date("document.all.myTime"); 2.获取日期和时间 f_get_datetime("document.all.myTime");

0 0