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

ASP+javascript的完整的日历使用

程序员文章站 2022-08-10 20:26:18
  第一步:保存下列文件为:calendar.asp <%@ language = vbscript %><% option explicit %><%fun...
 

第一步:保存下列文件为:calendar.asp

<%@ language = vbscript %>
<% option explicit %>
<%
function sfont(isize,sface,scolor,bscale)
 dim soutputstr
 soutputstr = "<font"
 if sface <> "" 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 = soutputstr
end function
on error resume next
dim datecntrl, dy, mo, yr, nextmonth, startwith, thismo, thisyr, thisdate,the_type
dim prevmonthlastdate, currmonthlastdate, i, j, lastnum, anydate,default_value

datecntrl= request("object")
default_value=request("value")
the_type=request("type")
if the_type<>"datetime" then
 the_type="date"
end if

if 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 if

nextmonth = false
%>
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=gb2312">
  <meta name="generator" content="microsoft frontpage 4.0">
  <meta name="progid" content="frontpage.editor.document">
  <style type="text/css">
 a
  { font-size: 13px; color: #000000;text-decoration: none }
 a:hover
 {color: #ff0000;
 }
  </style>
  <title>日历</title>
  <script language="javascript">
 //检查字符串是否为日期,返回值:false、true
function 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 < lthdatestr;i++)
 { if (datestr.charat(i)== -)
  {
   status++;
  }
  if (status>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) && (12>=month) && (31>=day) && (1<=day)) )
 {
     //alert ("invalid month or day!");
  return false;
 }
 if (!((year % 4)==0) && (month==2) && (day==29))
 {
  //alert ("this is not a leap year!");
  return false;
 }
 if ((month<=7) && ((month % 2)==0) && (day>=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<10)  mo="0"+mo;
               if (dy<10)  dy="0"+dy;
   
   <%if the_type="datetime" then%>
    top.opener.<%= datecntrl %>.value =yr+"-"+mo+"-"+dy+" "+userform.hour.value+":"+userform.minute.value+":"+userform.second.value;
   <%else%>
    top.opener.<%= datecntrl %>.value =yr+"-"+mo+"-"+dy;
   <%end if%>
   top.window.close();
              
               }
  
      <%if the_type="datetime" then%>
       self.location.href="calendar.?type=<%=the_type%>&object=<%= datecntrl %>&value="+yr+"-"+right(("0"+mo),2)+"-"+right(("0"+dy),2)+" "+userform.hour.value+":"+userform.minute.value+":"+userform.second.value;
   <%else%>
    self.location.href="calendar.asp?type=<%=the_type%>&object=<%= datecntrl %>&value="+yr+"-"+right(("0"+mo),2)+"-"+right(("0"+dy),2);
   <%end if%>
  }
  
  function savedate()
  {
   <%if the_type="datetime" then%>
    top.opener.<%= datecntrl %>.value ="<%= yr & "-" & right("0"+cstr(mo),2) & "-" & right("0"+cstr(dy),2) %>"+" "+userform.hour.value+":"+userform.minute.value+":"+userform.second.value