国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用ASP開發WEB日期選擇器

2019-11-18 20:17:43
字體:
來源:轉載
供稿:網友
  在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="POST" action="sample.htm" name="sample">
  <b><font face="Arial">Sample</font></b><p>
  <font face="Arial"><span style="font-size: 9pt; font-weight:

700">Date: </span>
  </font><input type="text" name="date" size="10" readonly>
  <a href="#SelectDate"

onClick="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');">
  <img border="0" src="images/date_picker.gif" width="24"

height="16"></a></p>
  <p><input type="submit" value="submit" name="B1"></p>
</form>
</body>
</html>
===========================================================

2、calendar.asp
===========================================================
<%
'WEB Calendar
'By Chaiwei 2002-7-31
'--------------------------------

'月份名稱定義
Dim Month_Name(12)
Month_Name(1) = "January"
Month_Name(2) = "February"
Month_Name(3) = "March"
Month_Name(4) = "APRil"
Month_Name(5) = "May"
Month_Name(6) = "June"
Month_Name(7) = "July"
Month_Name(8) = "August"
Month_Name(9) = "September"
Month_Name(10) = "October"
Month_Name(11) = "November"
Month_Name(12) = "December"

'年份處理,默認值為服務器當前年份
if request.querystring("year")<>"" then
    Year_var=cint(request.querystring("year"))
else
    Year_var=year(date())
end if

'上一年、下一年賦值
Previous_year=Year_var-1
Next_year=Year_var+1


'月份處理,默認值為服務器當前月份
if request.querystring("Month")<>"" then
    Month_var=cint(request.querystring("Month"))
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="JavaScript">

//前端日期選擇函數

function pick(v) {
    

window.opener.document.<%=request.querystring("form")%>.<%=request.qu

erystring("field")%>.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="0" leftmargin="0" onLoad="window.focus();">
<div align="center">
  <center>
  <table border="0" cellspacing="0" style="border-collapse: collapse"

width="100%" id="AutoNumber1" cellpadding="0">
    <tr>
      <td width="100%" bgcolor="#003063">
      <%
      '日歷表頭顯示
      %>
      <div align="center">
        <center>
        <table border="0" cellspacing="0" style="border-collapse:

collapse" width="100%" id="AutoNumber3" cellpadding="2">
          <tr>
            <td width="20%" align="center">
            <a

href="calendar.asp?year=<%=Previous_year%>&month=<%=Month_var%>&form=

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

)%>" title="Previous Year" class="page">7</a>
             <a

href="calendar.asp?year=<%=Year_var%>&month=<%=Previous_month%>&form=

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

)%>" title="Previous Month" class="page">3</a></td>
            <td width="60%" align="center"

class="title"><%response.write Month_Name(Month_var) & " " &

Year_var%></td>
            <td width="20%" align="center">
            <a

href="calendar.asp?year=<%=Year_var%>&month=<%=Next_month%>&form=<%=r

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

title="Next Month" class="page">4</a>
             <a

href="calendar.asp?year=<%=Next_year%>&month=<%=Month_var%>&form=<%=r

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

title="Next Year" class="page">8</a></td>
          </tr>
        </table>
        </center>
      </div>
      </td>
    </tr>
    <tr>
      <td width="100%">
      <div align="center">
        <center>
        <table border="0" cellspacing="0" style="border-collapse:

collapse" width="100%" id="AutoNumber2" cellpadding="3">
          <tr>
            <td align="center" bgcolor="#31659C"

class="title">Mon</td>
            <td align="center" bgcolor="#31659C"

class="title">Tur</td>
            <td align="center" bgcolor="#31659C"

class="title">Wed</td>
            <td align="center" bgcolor="#31659C"

class="title">Thu</td>
            <td align="center" bgcolor="#31659C"

class="title">Fri</td>
            <td align="center" bgcolor="#31659C"

class="title">Sat</td>
            <td align="center" bgcolor="#31659C"

class="title">Sun</td>
          </tr>
          <%
          '日歷內容 5行*7例 顯示
          '外層循環顯示控制行
          
          for i=0 to 4
          %>
          <tr>
          <%
          '內層循環顯示控制列
          
              for j=0 to 6
                  response.write "<td align='center'

class='dayTable'"
                  
                  '天數顯示,“今天”顯示
                  
                  if Current_day = date then
                      response.write " bgcolor='#FFFFE0'>"
                      %><a

href="javascript:pick('<%=Current_day%>');" title="Today"

class="day"><b><%=day(Current_day)%></b></a><%                  
                  else
                  
                      '天數顯示,非本月天數顯示
                  
                      if Month(Current_day) <> Month_var

then
                          response.write "

bgcolor='#F0F0F0'>"
                          %>
                          <a

href="javascript:pick('<%=Current_day%>');" title="<%=Current_day%>"

class="day"><font color="#CCCCCC"><%=day(Current_day)%></font></a><%
                      else
                          
                          '天數顯示,本月天數顯示
                          response.write ">"
                          %>
                          <a

href="javascript:pick('<%=Current_day%>');" title="<%=Current_day%>"

class="day"><%=day(Current_day)%></a><%
                      end if
                    
                  end if
                  
                  '天數累加推算
                  
                  Current_day = Current_day + 1
                response.write "</td>"
              next
          %>
          </tr>
          <%
          next
          %>
        </table>
        </center>
      </div>
      </td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>
===========================================================

[后記]

  其實這個日期選擇器通用性很大,稍加改動還可以在其它應用中發揮更多效力。比如,在開發日程安排的程序時,將其放在內嵌框架里,讓用戶在同一頁面不刷新的情況下方便選擇,安排事務更是方便有效。

2002-8-2
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 葫芦岛市| 民丰县| 望城县| 南陵县| 沧州市| 慈利县| 濮阳县| 德江县| 蕉岭县| 石棉县| 德江县| 阿鲁科尔沁旗| 中宁县| 武功县| 科技| 海南省| 万年县| 车险| 宜丰县| 逊克县| 河间市| 鄂托克前旗| 泸定县| 赫章县| 绥宁县| 日土县| 肃南| 广丰县| 广东省| 新竹县| 泊头市| 蒙自县| 邵武市| 和林格尔县| 西丰县| 同心县| 昂仁县| 旺苍县| 庄河市| 彰化县| 宜阳县|