选择显示字体大小

用asp开发web日期选择器


  在web结构程序开发中,日期数据在表单中输入可以采用很多种方法,常见的有:
  1、在文本框中让用户按规定好的日期格式直接输入。这种方法最简单,可是用户使用起来很麻烦,而且程序员还要在后台对输入的日期进行数据验证,所以显得很笨拙;
  2、用下拉列表列出年份、月份、天数由用户选择输入。这种方法更麻烦,用户操作看似比上一种方便了,可是每一个日期输入都需要程序员在后台对年份、月份、天数一一循环列出,而且在列出前或用户输入后还是要对日期信息进行验证,所以这种方法也不可取;
  3、用activex日历控件,在前台输入。这种方法很方便,可是唯一缺点也是最致命的一个弱点:需要每个客户端都要装有activex控件。

  最近,笔者用asp结合javascript,开发了这样一个模仿控件式的日期选择器。用户操作更直观、更方便;程序后台实现时可以在每次需要时很方便的调用,而不需要客户端安装任何程序。

  在此,将源代码贡献出来与大家一起分享。

[原理]

  使用页面通过打开定制窗口调用日期选择程序,并将使用页面内的formname,filedname元素属性传给日期选择程序。在日期选择程序中,用asp在后台计算并显示出日历,用户选择后,将日期值再传回使用页面的filed.value,最后自动关闭弹出窗口完成选择。

[源程序]

 1、sample.htm   (使用页面)
  2、calendar.asp (日期选择器程序)

1、sample.htm
========================================================
<html>
<head>
<title>calendar sample</title>
</head>
<body>
<form method=&quot;post&quot; action=&quot;sample.htm&quot; name=&quot;sample&quot;>
  <b><font face=&quot;arial&quot;>sample</font></b><p>
  <font face=&quot;arial&quot;><span style=&quot;font-size: 9pt; font-weight:

700&quot;>date: </span>
  </font><input type=&quot;text&quot; name=&quot;date&quot; size=&quot;10&quot; readonly>
  <a href=&quot;#selectdate&quot;

onclick=&quot;javascript:window.open('calendar.asp?form=sample&field=date'

,'','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=no,resi

zable=no,width=190,height=140');&quot;>
  <img border=&quot;0&quot; src=&quot;images/date_picker.gif&quot; width=&quot;24&quot;

height=&quot;16&quot;></a></p>
  <p><input type=&quot;submit&quot; value=&quot;submit&quot; name=&quot;b1&quot;></p>
</form>
</body>
</html>
===========================================================

2、calendar.asp
===========================================================
<%
'web calendar
'by chaiwei 2002-7-31
'--------------------------------

'月份名称定义
dim month_name(12)
month_name(1) = &quot;january&quot;
month_name(2) = &quot;february&quot;
month_name(3) = &quot;march&quot;
month_name(4) = &quot;april&quot;
month_name(5) = &quot;may&quot;
month_name(6) = &quot;june&quot;
month_name(7) = &quot;july&quot;
month_name(8) = &quot;august&quot;
month_name(9) = &quot;september&quot;
month_name(10) = &quot;october&quot;
month_name(11) = &quot;november&quot;
month_name(12) = &quot;december&quot;

'年份处理,默认值为服务器当前年份
if request.querystring(&quot;year&quot;)<>&quot;&quot; then
    year_var=cint(request.querystring(&quot;year&quot;))
else
    year_var=year(date())
end if

'上一年、下一年赋值
previous_year=year_var-1
next_year=year_var+1


'月份处理,默认值为服务器当前月份
if request.querystring(&quot;month&quot;)<>&quot;&quot; then
    month_var=cint(request.querystring(&quot;month&quot;))
else
    month_var=month(date())
end if

'上一月、下一月赋值
if month_var<=1 then
    next_month=month_var+1
    previous_month=1
else
    if month_var>=12 then
        next_month=12
        previous_month=month_var-1
    else
        next_month=month_var+1
        previous_month=month_var-1
    end if
end if

'当前天数定位计算
first_day=dateserial(year_var,month_var,1)
current_day=first_day-weekday(first_day)+2

%>
<html>
<head>
<title>calendar</title>
<script language=&quot;javascript&quot;>

//前端日期选择函数

function pick(v) {
    

window.opener.document.<%=request.querystring(&quot;form&quot;)%>.<%=request.qu

erystring(&quot;field&quot;)%>.value=v;
    window.close();
    return false;
}
</script>
<style>
<!--
.page        { text-decoration: none; color: #cae3ff; font-size:9pt;

font-family:webdings }
.daytable    { border: 1px dotted #e6e6e6; padding-left: 4;

padding-right: 4; padding-top: 1; padding-bottom: 1}
.day         { font-family: arial; font-size: 9pt; text-decoration:

underline; color: #000000 }
:hover.day   { font-family: arial; font-size: 9pt; text-decoration:

none; color: #ff0000 }
.title       { font-family: arial; font-size: 9pt; color: #ffffff;

font-weight: bold }
:hover.page  { text-decoration: underline; color: #ffffff;

font-family:webdings; font-size:9pt }
-->
</style>
</head>
<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot; onload=&quot;window.focus();&quot;>
<div align=&quot;center&quot;>
  <center>
  <table border=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot;

width=&quot;100%&quot; id=&quot;autonumber1&quot; cellpadding=&quot;0&quot;>
    <tr>
      <td width=&quot;100%&quot; bgcolor=&quot;#003063&quot;>
      <%
      '日历表头显示
      %>
      <div align=&quot;center&quot;>
        <center>
        <table border=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:

collapse&quot; width=&quot;100%&quot; id=&quot;autonumber3&quot; cellpadding=&quot;2&quot;>
          <tr>
            <td width=&quot;20%&quot; align=&quot;center&quot;>
            <a

href=&quot;calendar.asp?year=<%=previous_year%>&month=<%=month_var%>&form=

<%=request.querystring(&quot;form&quot;)%>&field=<%=request.querystring(&quot;field&quot;

)%>&quot; title=&quot;previous year&quot; class=&quot;page&quot;>7</a>
             <a

href=&quot;calendar.asp?year=<%=year_var%>&month=<%=previous_month%>&form=

<%=request.querystring(&quot;form&quot;)%>&field=<%=request.querystring(&quot;field&quot;

)%>&quot; title=&quot;previous month&quot; class=&quot;page&quot;>3</a></td>
            <td width=&quot;60%&quot; align=&quot;center&quot;

class=&quot;title&quot;><%response.write month_name(month_var) & &quot; &quot; &

year_var%></td>
            <td width=&quot;20%&quot; align=&quot;center&quot;>
            <a

href=&quot;calendar.asp?year=<%=year_var%>&month=<%=next_month%>&form=<%=r

equest.querystring(&quot;form&quot;)%>&field=<%=request.querystring(&quot;field&quot;)%>&quot;

title=&quot;next month&quot; class=&quot;page&quot;>4</a>
             <a

href=&quot;calendar.asp?year=<%=next_year%>&month=<%=month_var%>&form=<%=r

equest.querystring(&quot;form&quot;)%>&field=<%=request.querystring(&quot;field&quot;)%>&quot;

title=&quot;next year&quot; class=&quot;page&quot;>8</a></td>
          </tr>
        </table>
        </center>
      </div>
      </td>
    </tr>
    <tr>
      <td width=&quot;100%&quot;>
      <div align=&quot;center&quot;>
        <center>
        <table border=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:

collapse&quot; width=&quot;100%&quot; id=&quot;autonumber2&quot; cellpadding=&quot;3&quot;>
          <tr>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>mon</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>tur</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>wed</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>thu</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>fri</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>sat</td>
            <td align=&quot;center&quot; bgcolor=&quot;#31659c&quot;

class=&quot;title&quot;>sun</td>
          </tr>
          <%
          '日历内容 5行*7例 显示
          '外层循环显示控制行
          
          for i=0 to 4
          %>
          <tr>
          <%
          '内层循环显示控制列
          
              for j=0 to 6
                  response.write &quot;<td align='center'

class='daytable'&quot;
                  
                  '天数显示,“今天”显示
                  
                  if current_day = date then
                      response.write &quot; bgcolor='#ffffe0'>&quot;
                      %><a

href=&quot;javascript:pick('<%=current_day%>');&quot; title=&quot;today&quot;

class=&quot;day&quot;><b><%=day(current_day)%></b></a><%                  
                  else
                  
                      '天数显示,非本月天数显示
                  
                      if month(current_day) <> month_var

then
                          response.write &quot;

bgcolor='#f0f0f0'>&quot;
                          %>
                          <a

href=&quot;javascript:pick('<%=current_day%>');&quot; title=&quot;<%=current_day%>&quot;

class=&quot;day&quot;><font color=&quot;#cccccc&quot;><%=day(current_day)%></font></a><%
                      else
                          
                          '天数显示,本月天数显示
                          response.write &quot;>&quot;
                          %>
                          <a

href=&quot;javascript:pick('<%=current_day%>');&quot; title=&quot;<%=current_day%>&quot;

class=&quot;day&quot;><%=day(current_day)%></a><%
                      end if
                    
                  end if
                  
                  '天数累加推算
                  
                  current_day = current_day + 1
                response.write &quot;</td>&quot;
              next
          %>
          </tr>
          <%
          next
          %>
        </table>
        </center>
      </div>
      </td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>
===========================================================

[后记]

  其实这个日期选择器通用性很大,稍加改动还可以在其它应用中发挥更多效力。比如,在开发日程安排的程序时,将其放在内嵌框架里,让用户在同一页面不刷新的情况下方便选择,安排事务更是方便有效。

2002-8-2


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons