使用的是一个img作为按钮,一个iframe载入日期页面
<IMG id="ImgDate" style="LEFT: 137px; CURSOR: hand; POSITION: absolute; TOP: 1px" onclick="SetlstDate1Visible('TxtDate')" src="images/ImgBtn/frmMainDate.gif" width="21">
<IFRAME class="dtpMonth1" id="lstDate1" style="DISPLAY: none; Z-INDEX: 105; LEFT: 112px; WIDTH: 176px; POSITION: absolute; TOP: 152px; HEIGHT: 160px"
tabIndex="-1" name="lstDate1" src="frmDate.aspx" frameBorder="0" scrolling="no">
</IFRAME>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="frmDate.aspx.vb" Inherits="MOST_WEB.frmDate"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>dtpDate1</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<script language="javascript" src="comFuncs.js"></script>
<script language="JavaScript">
function RunNian(The_Year)//取得是否為潤年
{
if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))
return true;
else
return false;
}
function GetWeekday(The_Year,The_Month)
{
var Allday;
Allday = 0;
if (The_Year>2000)
{
for (i=2000 ;i<The_Year; i++) //計算從2000年開始到今年的天數
{
if (RunNian(i)){
Allday += 366;
}else{
Allday += 365;
}
}
for (i=2; i<=The_Month; i++)
{
switch (i)
{
case 2 : Allday += 31; break;
case 3 :
if (RunNian(The_Year)){
Allday += 29;
}else{
Allday += 28;
}
break;
case 4 : Allday += 31; break;
case 5 : Allday += 30; break;
case 6 : Allday += 31; break;
case 7 : Allday += 30; break;
case 8 : Allday += 31; break;
case 9 : Allday += 31; break;
case 10 : Allday += 30; break;
case 11 : Allday += 31; break;
case 12 : Allday += 30; break;
}
}
}
return (Allday+6)%7;
}
function chooseday(objName,The_Year,The_Month,The_Day)
{
var Firstday;
Firstday = GetWeekday(The_Year,The_Month);//取得星期幾
ShowCalender(objName,The_Year,The_Month,The_Day);
}
function showdate(objName,The_Year,The_Month,The_Day){//顯示日期,將所選的日期傳到textbox中顯示出來
var txtDate;
objName="TxtDate";
txtDate= objName;
var completely_date;
var cur_Month
var cur_Day
if (The_Month.toString().length==1){//給月前面加0
cur_Month="0"+The_Month
}else{
cur_Month=The_Month
}
if (The_Day.toString().length==1){//給日期前加0
cur_Day="0"+The_Day
}else{
cur_Day=The_Day
}
if (The_Day!=0)//調整日期的樣式
completely_date = The_Year + "/" + cur_Month + "/" + cur_Day;
else
completely_date = "No Choose";
parent.document.all(txtDate).innerText = completely_date;//顯示給textbox
}
function nextmonth(objName,The_Year,The_Month,The_Day)//選擇下個月
{
if (The_Month==12)
chooseday(objName,The_Year+1,1,The_Day);
else
chooseday(objName,The_Year,The_Month+1,The_Day);
}
function prevmonth(objName,The_Year,The_Month,The_Day)//選擇上一月
{
if (The_Month==1)
chooseday(objName,The_Year-1,12,The_Day);
else
chooseday(objName,The_Year,The_Month-1,The_Day);
}
function closeself(){
top.document.frames(1).document.frames(1).ObjLostFocus();
}
function ShowCalender(objName,The_Year,The_Month,The_Day)//
{
var Firstday=GetWeekday(The_Year,The_Month);
var showstr;
var Month_Day; //顯示月的天數
var ShowMonth; //顯示月
var today; //當前天
var k=0
today = new Date();
switch (The_Month)//根據月來確定天數
{
case 1 : ShowMonth = "01"; Month_Day = 31; break;
case 2 :
ShowMonth = "02";
if (RunNian(The_Year))
Month_Day = 29;
else
Month_Day = 28;
break;
case 3 : ShowMonth = "03"; Month_Day = 31; break;
case 4 : ShowMonth = "04"; Month_Day = 30; break;
case 5 : ShowMonth = "05"; Month_Day = 31; break;
case 6 : ShowMonth = "06"; Month_Day = 30; break;
case 7 : ShowMonth = "07"; Month_Day = 31; break;
case 8 : ShowMonth = "08"; Month_Day = 31; break;
case 9 : ShowMonth = "09"; Month_Day = 30; break;
case 10 : ShowMonth = "10"; Month_Day = 31; break;
case 11 : ShowMonth = "11"; Month_Day = 30; break;
case 12 : ShowMonth = "12"; Month_Day = 31; break;
}
showstr = "";//葉面的樣式
showstr = "<Table class=calender HEIGHT=100% width=100% cellpadding=0 cellspacing=0 border=0 bordercolor=red align=center valign=top>";
showstr += "<tr height=20 class='title1'><td colspan=6>期日を選ぶ</td><td align=right><IMG style='CURSOR: hand' onclick='closeself()' height='15' src='./images/imgbtn/close.gif' width='15'></td></tr>";
showstr += "<tr height=20 class='title2'><td width=3><img style='cursor:hand' src='./images/imgbtn/btnLeft.gif' onclick=prevmonth('" + objName + "',"+The_Year+","+The_Month+","+The_Day+")></td><td align=left colspan=5>" + The_Year + "年"+ShowMonth+"月"+"</td><td align=right width=30 ><img style='cursor:hand' onclick=nextmonth('" + objName + "',"+The_Year+","+The_Month+","+The_Day+") src='./images/imgbtn/btnRight.gif'></td></tr>";
showstr += "<tr><td align=center width=100% colspan=7>";
showstr += "<table cellpadding=0 cellspacing=0 border=0 bordercolor=#999999 width=100%>";
showstr += "<Tr align=center class='title3'> ";
showstr += "<td class=sun>日</td>";
showstr += "<td>月</td>";
showstr += "<td>火</td>";
showstr += "<td>水</td>";
showstr += "<td>木</td>";
showstr += "<td>金</td>";
showstr += "<td class=sat>土</td>";
showstr += "</Tr><tr>"; //上面是設置完成日期的頭部
k=k+1;
for (i=1; i<=Firstday; i++) //Firstday傳過來的當前月第一天是星期幾
{
showstr += "<Td align=center class=day> </Td>"; //將前面的天數置空
}
if(The_Day>Month_Day)
{
The_Day=Month_Day; //用選擇的天The_Day和當前月天數Month_Day比較
}
for (i=1; i<=Month_Day; i++)
{
if (The_Day==i){
bgColor = "dayselected";
}else{
bgColor = "day";
}
if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate())){
showstr += "<td align=center class=" + bgColor + " style='CURSOR: hand;BACKGROUND-POSITION: center center;BACKGROUND-REPEAT: no-repeat;BACKGROUND-IMAGE: url(./Images/imgbtn/date.gif);' onclick=chooseday('" + objName + "'," + The_Year + "," + The_Month + "," + i + ")>" + i ;
}else{
showstr += "<td align=center class=" + bgColor + " style='cursor:hand' onclick=chooseday('" + objName + "'," + The_Year + "," + The_Month + "," + i + ")>" + i ;
}
showstr += "</td>";
Firstday = (Firstday + 1)%7;
if ((Firstday==0) && (i!=Month_Day)) {
showstr += "</tr><tr>";
k=k+1;
}
}
if (Firstday!=0) //Firstday傳過來的當前月第一天是星期幾
{
for (i=Firstday; i<7; i++)
showstr += "<td align=center class=day> </td>";
showstr += "</tr>";
}
showstr += "</tr><tr>"
if (k==5){
showstr += "<td colspan=7 class=day> </td></tr><tr>";
}
var curMonth;
var curDay;
if ((today.getMonth()+1).toString().length==1){
curMonth="0"+(today.getMonth()+1);
}else{
curMonth=(today.getMonth()+1);
}
if (today.getDate().toString().length==1){
curDay="0"+today.getDate();
}else{
curDay=today.getDate();
}
showstr +="<td class='title4' colspan=2><img src='./Images/imgbtn/date.gif'></td><td align=left colspan=5 class='title4' style='CURSOR: hand;' onclick=getDtpDate('');>  今日:"+today.getYear()+"/"+curMonth+"/"+curDay+"</td>"
showstr += "</tr></table></td></tr></table>";
document.all(objName).innerHTML= showstr;
showdate("txtFrom",The_Year,The_Month,The_Day)
}
function getDtpDate(strDate){
today = new Date();
if (!DcheckDate(strDate,"yyyy/mm/dd")){
The_Year = today.getYear();
The_Month = today.getMonth() + 1;
The_Day = today.getDate();
Firstday = GetWeekday(The_Year,The_Month);
}else{
var curday=new Date(strDate)
The_Year = curday.getYear();
The_Month = curday.getMonth() + 1;
The_Day = curday.getDate();
Firstday = GetWeekday(The_Year,The_Month);
}
ShowCalender("Date1",The_Year,The_Month,The_Day);
}
</script>
</HEAD>
<body>
<form id="Form1" method="post">
<TABLE style="LEFT: 0px; POSITION: absolute; TOP: 0px" cellSpacing="0" cellPadding="0"
border="0">
<TR>
<TD id="Date1"><FONT face="MS UI Gothic"></FONT></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>