一个关于日期选择的很实用的小东西
来源:互联网 发布:sqlserver安装图解 编辑:程序博客网 时间:2024/05/13 10:35
以前做页面时经常需要制作日期选择框,例如出生日期、查询日期等等,通常的做法是制作三个下拉列表(select),分别用于选择年、月、日,但该方法在各方面的表现都很令人不耐烦,于是我做了这个日期选择页面,它不是组件,也不是函数,只是一个普通的ASP页面,用于返回用户选择的日期变量。
************************************************************************
<%
'day.asp
%>
<html>
<head>
<title>选择日期 </title>
<style type=text/css>
<!--
body{margin:0;font-size:9pt;color:#5E639B}
td{font-size:9pt;color:#000000}
a:link {color:#000000;text-decoration: none}
a:visited {color:#000000;text-decoration: none}
a:active {color:#000000;text-decoration: none}
a:hover { color:#ff3333;text-decoration: none}
-->
</style>
<Script Language="JavaScript">
function getDay(v){
window.opener.document.<%=request.querystring("form")%>.<%=request.querystring("field")%>.value=v;
window.close();
return false;
}
</Script>
</head>
<body bgcolor=#ffffff onBlur="window.focus()">
<%
oldDate=request("oldDate")
if not isDate(oldDate) then oldDate=date
yy=year(cdate(oldDate))
mm=month(cdate(oldDate))
if request("yy")<>"" then yy=request("yy")
if request("mm")<>"" then mm=request("mm")
if yy="" then yy=year(date)
if mm="" then mm=month(date)
if mm>12 then mm=1:yy=yy+1
if mm<1 then mm=12:yy=yy-1
dim m(12)
m(1)=31
m(3)=31
m(5)=31
m(7)=31
m(8)=31
m(10)=31
m(12)=31
m(2)=28
m(4)=30
m(6)=30
m(9)=30
m(11)=30
if (yy mod 4=0 and yy mod 100<>0) or yy mod 400=0 then m(2)=29
mms=m(mm)
week1=(weekday(cdate(yy & "-" & mm & "-1"))-1)
%>
<table width=250 cellspacing=1 cellpadding=0 bgcolor=#FFDFDF align=center>
<tr>
<td colspan=7 align=center>
<table width=100% height=20 cellspacing=0 cellpadding=0>
<tr height=20>
<td width=30 align=center>
<a href=day.asp?form=<%=request("form")%>&field=<%=request("field")%>&yy=<%=(yy-1)%>&mm=<%=mm%>>
<font face=webdings style=color:#000000 title="上一年">7</font>
</a>
<td width=30 align=center>
<a href=day.asp?form=<%=request("form")%>&field=<%=request("field")%>&mm=<%=(mm-1)%>&yy=<%=yy%>>
<font face=webdings style=color:#000000 title="上一月">3</font>
</a>
<td width=130 align=center style="FONT:9pt Verdana,Geneva,sans-serif;color:#CD0101">
<b><%=yy%> 年 <%=mm%> 月</b>
<td width=30 align=center>
<a href=day.asp?form=<%=request("form")%>&field=<%=request("field")%>&mm=<%=(mm+1)%>&yy=<%=yy%>>
<font face=webdings style=color:#000000 title="下一月">4</font>
</a>
<td width=30 align=center>
<a href=day.asp?form=<%=request("form")%>&field=<%=request("field")%>&yy=<%=(yy+1)%>&mm=<%=mm%>>
<font face=webdings style=color:#000000 title="下一年">8</font>
</a>
</table>
<tr bgcolor=#ffffff height=20>
<td width=35 align=center bgcolor=#FFF4F4 style=color:#ff6633>日
<td width=35 align=center bgcolor=#FFF4F4>一
<td width=35 align=center bgcolor=#FFF4F4>二
<td width=35 align=center bgcolor=#FFF4F4>三
<td width=35 align=center bgcolor=#FFF4F4>四
<td width=35 align=center bgcolor=#FFF4F4>五
<td width=35 align=center bgcolor=#FFF4F4>六
<%
if week1<>0 then
response.write "<tr>"
for i=1 to week1
response.write "<td width=35 height=20 bgcolor=#ffffff> "
next
end if
for i=1 to mms
if (i+week1-1) mod 7=0 then response.write "<tr>"
response.write "<td width=35 height=20 align=center bgcolor=#ffffff>"
if cdate(yy & "-" & mm & "-" & i)=date() then
%>
<input type=button value=<%=i%>
style="BORDER:#CD0101 1px groove;width:30;height:16;font-size:9pt;background-color:#FFD9D9;color:#CD0101"
onclick="javascript:getDay('<%=yy%>-<%=mm%>-<%=i%>');" title="<%=yy%>年<%=mm%>月<%=i%>日(今天)">
<%
else
%>
<input type=button value=<%=i%>
style="BORDER:#000000 1px groove;width:30;height:16;font-size:9pt;background-color:#ffffff;color:#000000"
onclick="javascript:getDay('<%=yy%>-<%=mm%>-<%=i%>');" title="<%=yy%>年<%=mm%>月<%=i%>日">
<%
end if
next
if (mms+week1) mod 7<>0 then
for i=1 to (7-((mms+week1) mod 7))
response.write "<td width=35 height=20 bgcolor=#ffffff> "
next
end if
%>
</table><br>
<div align=center><a href="javascript:window.close()">〖关闭本窗口〗</a></div>
</body>
</html>
************************************************************************
调用day.asp页面的代码:
<form name=form1>
<input name=date1 value=<%=date()%> readonly onClick="JavaScript:window.open('day.asp?form=form1&field=date1&oldDate='+this.value,'','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width=250,height=200,top=220,left=250');"
</form>
************************************************************************
其中,打开day.asp页面时,需要传递几个参数,分别是:
1)form:日期选择框所在的表单名称,本例为form1,可根据应用自行更改
2)field:日期选择框的名称,本例为date1,可根据应用自行更改
3)olddate:日期选择框的当前值,不需改动。
我叫“积木”,欢迎和我成为朋友!
http://www.ecolor99.com/jim
- 一个关于日期选择的很实用的小东西
- 纪录一些实用的小东西
- 批处理的一个小东西
- 一个未完成的小东西
- 关于回文数的小东西
- 关于继承的一点小东西
- 一个每日一贴的小东西
- 贴一个 自己写的小东西....
- CSAPP中一个有意思的小东西
- 关于子查询的一些小东西
- PB关于日期相关的实用函数
- 很low的小东西(即时通讯)
- 非常实用的选择输入日期的特效,JS代码。
- 一个基于JS的日期选择控件
- 一个不平凡的日期选择控件
- 一个不错的日期选择框
- javascript实现的一个日期选择控件
- 一个非常好的JS日期选择控件
- 1.1 什么是编程语言:如何像计算机专家一样思考(C++版)
- SharpDevelop带你进入免费的C# 编程环境
- DLL全局钩子
- 两个控制显示格式的函数(自动换行、自动省略)
- 一个统计当前在线用户的解决方案,可以在聊天室、论坛、网站中使用
- 一个关于日期选择的很实用的小东西
- <选择>--给那些正在或将要找工作的人们!
- 如何在vc++中旋转位图---任意角度
- 由内存对齐讨论想到位图旋转
- 《黑客帝国II》:人类明天的真实命运?(转载)
- 《黑客帝国》或颠倒的两面
- 组件实例的命名规则
- Delphi代码创建形式规范
- 异类的屏幕保护