一个web日期选择代码 ( 积分: 0 )

  • 主题发起人 主题发起人 wzquan
  • 开始时间 开始时间
W

wzquan

Unregistered / Unconfirmed
GUEST, unregistred user!
<%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;WebForm2.aspx.vb&quot; Inherits=&quot;Web6.WebForm2&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio .NET 7.1&quot;>
<meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic .NET 7.1&quot;>
<meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;>
<meta name=&quot;vs_targetSchema&quot; content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;>
<style>
.tr { CURSOR: hand }
</style>
<script language=&quot;javascript&quot;>
var curYear=new Date().getYear();
var curMonth=new Date().getMonth()+1;
//var curYear=&quot;<% Year(now) %>&quot;
//var curMonth=&quot;<% Month(now) %>&quot;
function fStart()
{
ViewDateDiv.style.display=&quot;block&quot;;
ViewDateGrid()
}
function MonthMinus() //月数减一
{
if (curMonth<=1)
{
curYear-=1;
curMonth=12;
}
else
{
curMonth-=1;
}
ViewDateGrid();
}
function MonthAdd() //月数加一
{
if (curMonth>=12)
{
curYear+=1;
curMonth=1;
}
else
{
curMonth+=1;
}
ViewDateGrid();
}
//下面的代码在表格中写入数据
function ViewDateGrid()
{
//var val=curYear+&quot;-&quot;+curMonth+&quot;-1&quot;;
var val=curYear+&quot;/&quot;+curMonth+&quot;/1&quot;;
//var myArray=new Array()
//myArray=val.split(&quot;-&quot;);
//var myNewDate=new Date(myArray[0],myArray[1],myArray[2]);
var myNewDate=new Date(val);
var myWeek=myNewDate.getDay();
var myDays=getDays(curYear,curMonth);
var i,iRow,iCol,j;
iRow=2;
iCol=myWeek;
//var myRowIndex=event.parentElement.rowIndex;
window.ViewDatetable_1.rows[0].cells(1).innerHTML=curYear+&quot;年&quot;+curMonth+&quot;月&quot;;
//下面的代码清除表格中的数据
for(i=2;i<=7;i++)
{
for (j=0;j<=6;j++)
{
window.ViewDatetable_1.rows.cells(j).innerHTML=&quot;&quot;;
}
}
for(i=1;i<=myDays;i++)
{
window.ViewDatetable_1.rows[iRow].cells(iCol).innerHTML=i;
//window.ViewDatetable_1.row[iRow].cells(iCol).style.fontcolor=&quot;blue&quot;;
if((iCol+1) % 7==0)
{
iRow+=1;
iCol=0;
}
else
{
iCol+=1;
}
}

}
function getDays(myYear,myMonth)
{
var mytDays;
switch(myMonth)
{
case 1: mytDays=31; break;
case 3: mytDays=31; break;
case 5: mytDays=31; break;
case 7: mytDays=31; break;
case 8: mytDays=31; break;
case 10: mytDays=31; break;
case 12: mytDays=31; break;

case 4: mytDays=30; break;
case 6: mytDays=30; break;
case 9: mytDays=30; break;
case 11: mytDays=30; break;
case 2:
if (isLeapYear(myYear))
{
mytDays=29;
}
else
{
mytDays=28;
}
}
return(mytDays);
}
function isLeapYear(year)
{
return ((year %4==0 &amp;&amp; year %100!=0) || (year %400==0));
}

// var myleft=document.getElementById(&quot;table1&quot;).offsetLeft;
//var mytop=document.getElementById(&quot;table1&quot;).offsetTop;
function clicktable()
{
var myRowIndex=event.srcElement.parentElement.rowIndex;
if (myRowIndex>=2)
{
var myColIndex=event.srcElement.cellIndex;
var mySelStr=window.ViewDatetable_1.rows[myRowIndex].cells(myColIndex).innerHTML;
//alert(myColIndex+&quot;==&quot;+myRowIndex+&quot;==&quot;+mySelStr+&quot;==&quot;+curYear+&quot;--&quot;+curMonth);
if(mySelStr.length>0)
{
document.getElementById(&quot;TextBox1&quot;).innerText=curYear+&quot;-&quot;+curMonth+&quot;-&quot;+mySelStr;
//div1.innerHTML=window.ViewDatetable_1.rows[myRowIndex].cells(myColIndex).innerHTML;
//document.getElementById(&quot;TextBox1&quot;).innerHTML=curYear+&quot;-&quot;+curMonth+&quot;-&quot;+mySelStr;
//alert(curYear+&quot;-&quot;+curMonth+&quot;-&quot;+mySelStr);
document.getElementById(&quot;ViewDateDiv&quot;).style.display=&quot;none&quot;;
//ViewDateDiv.style.display=&quot;none&quot;;
}
}
}
function myMouseOver()
{

}
</script>
</HEAD>
<body MS_POSITIONING=&quot;GridLayout&quot; onload=&quot;ViewDateGrid()&quot;>
<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot; target=&quot;main&quot;>
<FONT face=&quot;宋体&quot;>
<asp:TextBox id=&quot;TextBox1&quot; style=&quot;Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 8px&quot; runat=&quot;server&quot;
Height=&quot;22px&quot; Width=&quot;155px&quot;></asp:TextBox>
<asp:Button id=&quot;Button1&quot; style=&quot;Z-INDEX: 103; LEFT: 200px; POSITION: absolute; TOP: 8px&quot; runat=&quot;server&quot;
Height=&quot;21px&quot; Width=&quot;22px&quot; Text=&quot;▼&quot;></asp:Button>
<asp:Label id=&quot;Label1&quot; style=&quot;Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 16px&quot; runat=&quot;server&quot;
Height=&quot;21px&quot; Width=&quot;32px&quot; Font-Size=&quot;10pt&quot; Font-Names=&quot;宋体&quot; BackColor=&quot;Transparent&quot;>日期</asp:Label>
<div id=&quot;ViewDateDiv&quot; style=&quot;BORDER-RIGHT:#008080 double; BORDER-TOP:#008080 double; DISPLAY:block; Z-INDEX:101; LEFT:8px; BORDER-LEFT:#008080 double; WIDTH:152px; BORDER-BOTTOM:#008080 double; POSITION:absolute; TOP:32px; BACKGROUND-COLOR:#eeece8&quot;>
<table border=&quot;1&quot; width=&quot;10%&quot; id=&quot;ViewDatetable_1&quot; style=&quot;FONT-SIZE: 9pt; FONT-FAMILY: 宋体; BORDER-COLLAPSE: collapse&quot;
onclick=&quot;clicktable()&quot; onmouseover=&quot;myMouseOver()&quot;>
<tr>
<td align=&quot;center&quot; style=&quot;WIDTH: 24px&quot;>
<div id=&quot;DivMinus&quot; style=&quot;WIDTH:24px;CURSOR:hand;HEIGHT:12px&quot; onclick=&quot;MonthMinus()&quot;>&amp;lt;&amp;lt;</div>
</td>
<td colspan=&quot;5&quot; align=&quot;center&quot;>
</td>
<td>
<div id=&quot;DivAdd&quot; style=&quot;WIDTH:16px;CURSOR:hand;HEIGHT:12px&quot; onclick=&quot;MonthAdd()&quot;>&amp;gt;&amp;gt;</div>
</td>
</tr>
<tr>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>星期<br>
日</td>
<td nowrap align=&quot;center&quot;>星期<br>
一</td>
<td nowrap align=&quot;center&quot;>星期<br>
二</td>
<td nowrap align=&quot;center&quot;>星期<br>
三</td>
<td nowrap align=&quot;center&quot;>星期<br>
四</td>
<td nowrap align=&quot;center&quot;>星期<br>
五</td>
<td nowrap align=&quot;center&quot;>星期<br>
六</td>
</tr>
<tr class=&quot;tr&quot;>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
<tr class=&quot;tr&quot;>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
<tr class=&quot;tr&quot;>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
<tr class=&quot;tr&quot;>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
<tr class=&quot;tr&quot;>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
<tr>
<td nowrap align=&quot;center&quot; style=&quot;WIDTH: 36px&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
<td nowrap align=&quot;center&quot;>
</td>
</tr>
</table>
</div>
<asp:Button id=&quot;Button2&quot; style=&quot;Z-INDEX: 105; LEFT: 56px; POSITION: absolute; TOP: 208px&quot; runat=&quot;server&quot;
Width=&quot;104px&quot; Text=&quot;Button&quot;></asp:Button>
</FONT>
</form>
</body>
</HTML>
 
后退
顶部