|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
想法是和程序员的想法不一样的.至于为什么.大家去想一想.跟心理学有关的第一步:保留以下文件为:CALENDAR.ASP
<%@LANGUAGE=VBScript%>
<%OptionExplicit%>
<%
FunctionsFont(iSize,sFace,sColor,bScale)
DimsOutputStr
sOutputStr="<FONT"
ifsFace""then
sOutputStr=sOutputStr&"FACE="&sFace&""
else
sOutputStr=sOutputStr&"FACE=Helv"
endif
ifiSize=""then
iSize=1
endif
ifbScalethen
iSize=cInt(iSize*1)
endif
sOutputStr=sOutputStr&"SIZE="&iSize
ifsColor""then
sOutputStr=sOutputStr&"COLOR="&sColor
endif
sOutputStr=sOutputStr&">"
sFont=sOutputStr
EndFunction
OnErrorResumeNext
Dimdatecntrl,Dy,Mo,Yr,nextmonth,startwith,thisMo,thisYr,thisDate,the_type
DimprevMonthLastDate,currMonthLastDate,i,j,lastnum,AnyDate,default_value
datecntrl=Request("object")
default_value=request("value")
the_type=request("type")
ifthe_type"datetime"then
the_type="date"
endif
ifdefault_value=""then
Yr=year(date)
Mo=month(date)
Dy=day(date)
else
dimpos1
dimdeal_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))
iftrim(the_type)="date"then
Dy=cint(mid(deal_value,pos1+1))
else
dimH,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))
endif
endif
nextmonth=false
%>
<HTML>
<HEAD>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<metaname="GENERATOR"content="MicrosoftFrontPage4.0">
<metaname="ProgId"content="FrontPage.Editor.Document">
<styletype="text/CSS">
A
{FONT-SIZE:13px;COLOR:#000000;TEXT-DECORATION:none}
A:hover
{COLOR:#ff0000;
}
</style>
<TITLE>日历</TITLE>
<SCRIPTLANGUAGE="JavaScript">
//反省字符串是不是为日期,前往值:false、true
functionf_chkDate(datestr)
{
varlthdatestr
if(datestr!="")
lthdatestr=datestr.length;
else
lthdatestr=0;
vartmpy="";
vartmpm="";
vartmpd="";
//vardatestr;
varstatus;
status=0;
if(lthdatestr==0)
returnfalse;
if(lthdatestr>10)
returnfalse;
for(i=0;i<lthdatestr;i++)
{if(datestr.charAt(i)==-)
{
status++;
}
if(status>2)
{
//alert("Invalidformatofdate!");
returnfalse;
}
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=newString(tmpy);
month=newString(tmpm);
day=newString(tmpd);
//tempdate=newString(year+month+day);
//alert(tempdate);
if((tmpy.length!=4)||(tmpm.length>2)||(tmpd.length>2))
{
//alert("Invalidformatofdate!");
returnfalse;
}
if(!((1<=month)&&(12>=month)&&(31>=day)&&(1<=day)))
{
//alert("Invalidmonthorday!");
returnfalse;
}
if(!((year%4)==0)&&(month==2)&&(day==29))
{
//alert("Thisisnotaleapyear!");
returnfalse;
}
if((month<=7)&&((month%2)==0)&&(day>=31))
{
//alert("Thismonthisasmallmonth!");
returnfalse;
}
if((month>=8)&&((month%2)==1)&&(day>=31))
{
//alert("Thismonthisasmallmonth!");
returnfalse;
}
if((month==2)&&(day==30))
{
//alert("TheFebryaryneverhasthisday!");
returnfalse;
}
returntrue;
}
functionright(str,number)
{
returnstr.substr(str.length-number,str.length);
}
functionsetDate(Dy,Mo,Yr,vBool)
{
if(vBool)
{
if(Mo<10)Mo="0"+Mo;
if(Dy<10)Dy="0"+Dy;
<%ifthe_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;
<%endif%>
top.window.close();
}
<%ifthe_type="datetime"then%>
self.location.href="calendar.asp?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);
<%endif%>
}
functionsaveDate()
{
<%ifthe_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;
<%else%>
top.opener.<%=datecntrl%>.value="<%=Yr&"-"&right("0"+cstr(Mo),2)&"-"&right("0"+cstr(Dy),2)%>";
<%endif%>
top.window.close();
}
</SCRIPT>
</HEAD>
<BODYbgcolor="#CCFFFF">
<FORMNAME="userform">
<TABLEWIDTH="100%"CELLPADDING="2"CELLSPACING="0">
<TR>
<TDALIGN="left">
<%=sFont("2","宋体","",True)%>
<%=writeYears(Yr)%>
</TD>
<TDALIGN="right">
<%=sFont("2","宋体","",True)%>
<%=writeMonths(Mo)%>
</TD>
</TR>
</TABLE>
<TABLEWIDTH="100%"BORDER="1"BORDERCOLOR="Silver"CELLPADDING="2"CELLSPACING="0">
<%
functionnextDate(startwith,maxdays)
startwith=startwith+1
ifstartwith>maxdaysthen
startwith=1
endif
nextDate=startwith
endfunction
functionGetLastDay(Mo,Yr)
ifMo=2then
if(YrMod4)=0then
GetLastDay=29
else
GetLastDay=28
endif
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
endif
endfunction
functionGetFirstDayOffset(Mo,Yr)
GetFirstDayOffset=weekday(Mo&"/01/"&Yr)-1
endfunction
functionwriteMonths(selMo)
dimi,selstr
selstr="<SELECTNAME=MonthsonChange=setDate("&Dy&",this.selectedIndex+1,"&Yr&",false);>"
fori=1to12
ifselMo=ithen
selstr=selstr&"<OPTIONSELECTED>"&MonthName(i)
else
selstr=selstr&"<OPTION>"&MonthName(i)
endif
next
selstr=selstr&"</SELECT>"
writeMonths=selstr
endfunction
functionwriteYears(selYear)
dimi,selstr
selstr="<SELECTNAME=YearsonChange=setDate("&Dy&","&Mo&",this.options[this.selectedIndex].value,false);>"
fori=1900to2100
ifselYear=ithen
selstr=selstr&"<OPTIONSELECTEDVALUE="&i&">"&i&"年"
else
selstr=selstr&"<OPTIONVALUE="&i&">"&i&"年"
endif
next
selstr=selstr&"</SELECT>"
writeYears=selstr
endfunction
prevMonthLastDate=GetLastDay((Mo-1),Yr)
currMonthLastDate=GetLastDay(Mo,Yr)
startwith=(prevMonthLastDate-GetFirstDayOffset(Mo,Yr))
%>
<TR>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>日</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>一</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>二</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>三</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>四</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>五</B>
</TD>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="Gray"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000"style="font-family:Helv,Arial;font-size:10pt;">
<%=sFont("2","宋体","#FFFFFF",True)%>
<B>六</B>
</TD>
</TR>
<%Forj=1to6%>
<TR>
<%Fori=1to7%>
<%ifj=1then%>
<%startwith=nextDate(startwith,prevMonthLastDate)%>
<%ifstartwith=Dyandstartwith<7then%>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="#AAAAAA"BORDERCOLOR="#AAAAAA"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#AAAAAA">
<%else%>
<TDWIDTH="20"HEIGHT="20"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%endif%>
<%thisYr=Yr%>
<%=sFont("2","宋体","",True)%>
<%ifstartwith<7then%>
<B>
<%thisMo=Mo%>
<%else%>
<%thisMo=Mo-1%>
<%ifthisMo=0then%>
<%thisMo=12%>
<%thisYr=Yr-1%>
<%endif%>
<%endif%>
<AHREF="javascript:setDate(<%=startwith%>,<%=thisMo%>,<%=thisYr%>,false);">
<%response.writestartwith%>
</A></B>
</TD>
<%else%>
<%lastnum=startwith%>
<%startwith=nextDate(startwith,currMonthLastDate)%>
<%iflastnum>startwiththen%>
<%nextmonth=true%>
<%endif%>
<%ifstartwith=Dyandnotnextmonththen%>
<TDWIDTH="20"HEIGHT="20"BGCOLOR="#AAAAAA"BORDERCOLOR="#AAAAAA"BORDERCOLORDARK="#AAAAAA"BORDERCOLORLIGHT="#FFFFFF">
<%else%>
<TDWIDTH="20"HEIGHT="20"BORDERCOLOR="Silver"BORDERCOLORDARK="#FFFFFF"BORDERCOLORLIGHT="#000000">
<%endif%>
<%thisYr=Yr%>
<%ifnotnextmonththen%>
<B>
<%thisMo=Mo%>
<%else%>
<%thisMo=Mo+1%>
<%ifthisMo=13then%>
<%thisMo=1%>
<%thisYr=Yr+1%>
<%endif%>
<%endif%>
<%=sFont("2","宋体","",True)%>
<AHREF="javascript:setDate(<%=startwith%>,<%=thisMo%>,<%=thisYr%>,false);">
<%response.writestartwith%>
</A></B>
</TD>
<%endif%>
<%Next%>
</TR>
<%Next%>
</TABLE>
<table>
<tr>
<td>
<%ifthe_type="datetime"then%>
<selectsize="1"name="hour">
<%
fori=0to23
if(i=H)then
response.write"<optionselectedvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"时"+"</option>"
else
response.write"<optionvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"时"+"</option>"
endif
next
%>
</select>
<selectsize="1"name="minute">
<%
fori=0to59
if(i=M)then
response.write"<optionselectedvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"分"+"</option>"
else
response.write"<optionvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"分"+"</option>"
endif
next
%>
</select>
<selectsize="1"name="second">
<%
fori=0to59
if(i=S)then
response.write"<optionselectedvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"秒"+"</option>"
else
response.write"<optionvalue="+right("0"+cstr(i),2)+">"+right("0"+cstr(i),2)+"秒"+"</option>"
endif
next
%>
</select>
<%endif%>
</td>
</tr>
</table>
<CENTER>
<INPUTTYPE="button"id="ok"VALUE="断定"><INPUTTYPE="button"VALUE="作废">
</CENTER>
</FORM>
<scriptlanguage="javascript">
varstrDate=<%=Yr%>+"-"+right(("0"+<%=Mo%>),2)+"-"+right(("0"+<%=Dy%>),2);
if(f_chkDate(strDate))
document.all.ok.disabled=false;
else
document.all.ok.disabled=true;
</script>
</BODY>
</HTML>
第二步:保留以下文件为:JavaScriptdate.js
functionf_get_date(object_name){
varobject_value="";
eval("object_value="+object_name+".value");
if(!f_chkDate(object_value)){
varv_today=newDate();
object_value=v_today.getYear()+"-"+(v_today.getMonth()+1)+"-"+(v_today.getDate());
}
open(calendar.asp?type=date&object=+object_name+&value=+object_value,calendar,resizable=yes,toolbar=no,scrollbars=no,directories=no,menubar=no,width=180,height=240);
}
//猎取日用时间函数
functionf_get_datetime(object_name){
varobject_value="";
eval("object_value="+object_name+".value");
open(calendar.asp?type=datetime&object=+object_name+&value=+object_value,calendar,resizable=yes,toolbar=no,scrollbars=no,directories=no,menubar=no,width=210,height=270);
}
//反省字符串是不是为日期,前往值:false、true
functionf_chkDate(datestr)
{
varlthdatestr
if(datestr!="")
lthdatestr=datestr.length;
else
lthdatestr=0;
vartmpy="";
vartmpm="";
vartmpd="";
//vardatestr;
varstatus;
status=0;
if(lthdatestr==0)
returnfalse;
if(lthdatestr>10)
returnfalse;
for(i=0;i<lthdatestr;i++)
{if(datestr.charAt(i)==-)
{
status++;
}
if(status>2)
{
//alert("Invalidformatofdate!");
returnfalse;
}
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=newString(tmpy);
month=newString(tmpm);
day=newString(tmpd);
//tempdate=newString(year+month+day);
//alert(tempdate);
if((tmpy.length!=4)||(tmpm.length>2)||(tmpd.length>2))
{
//alert("Invalidformatofdate!");
returnfalse;
}
if(!((1<=month)&&(12>=month)&&(31>=day)&&(1<=day)))
{
//alert("Invalidmonthorday!");
returnfalse;
}
if(!((year%4)==0)&&(month==2)&&(day==29))
{
//alert("Thisisnotaleapyear!");
returnfalse;
}
if((month<=7)&&((month%2)==0)&&(day>=31))
{
//alert("Thismonthisasmallmonth!");
returnfalse;
}
if((month>=8)&&((month%2)==1)&&(day>=31))
{
//alert("Thismonthisasmallmonth!");
returnfalse;
}
if((month==2)&&(day==30))
{
//alert("TheFebryaryneverhasthisday!");
returnfalse;
}
returntrue;
}
第三步:在页中到场以下示例:(利用页)
<scriptlanguage="javascript"src="JavaScriptdate.js"></script>
<inputclass="input"style="cursor:hand";name="myTime"type="text"id="myTime"size="16"value=""readonly="true">
1.猎取日期:
<scriptlanguage="javascript"event="onclick"for="myTime">
f_get_date("document.all.myTime");
</script>
2.猎取日期和工夫
<scriptlanguage="javascript"event="onclick"for="myTime">
f_get_datetime("document.all.myTime");
</script>
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件 |
|