我想用下面的代碼構建一個HTML日期選擇器,我沒有使用jquery,因爲我正在讀取經典asp頁面的返回值。HTML手動內置日期選擇器
<%@ Language=VBScript %>
<% Response.Expires = 0 %>
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="../css/Intranet.css">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function window_onload() {
mydate= new Date()
theMonth.selectedIndex = mydate.getMonth();
theYear.selectedIndex = mydate.getYear()-1940;
window.returnValue = (mydate.getMonth()+1) + "/" + mydate.getDate() + "/" + mydate.getYear();
display_calendar();
}
function navigateMonth(direction) {
if (direction==1)
if (theMonth.selectedIndex==11)
{
theMonth.selectedIndex = 0;
theYear.selectedIndex = theYear.selectedIndex + 1;
}
else
theMonth.selectedIndex = theMonth.selectedIndex + 1;
else
if (theMonth.selectedIndex==0)
{
theMonth.selectedIndex = 11;
theYear.selectedIndex = theYear.selectedIndex - 1;
}
else
theMonth.selectedIndex = theMonth.selectedIndex - 1;
display_calendar();
}
function display_calendar() {
for(i=0;i<42;i++) thisCell(i).innerHTML = " ";
d = new Date(theYear.value, theMonth.value, 1)
d_next = new Date(theYear.value, theMonth.value, 1)
currdate = new Number(theMonth.value)
if (currdate == 3 && theYear.value == 2011)
{
d_next = new Date(2011, 4, 2);
if (d.getDate() != 1){
d.setDate(d.getDate() + 1);
}
else {
d_next.setDate(d_next.getDate() - 1);
}
}
else
{
d_next.setMonth(currdate+1);
}
if (currdate==3 && theYear.value==2005)
{
d = new Date(theYear.value, 3, 1, 23, 59, 00)
d_next = new Date(theYear.value, 4, 1, 23, 59, 00)
currdate = new Number(theMonth.value)
}
for(i=d.getDay();i<Math.round((d_next-d)/86400000+d.getDay());i++)
{
if (thisCell(i))
{
thisCell(i).innerHTML = "<p style='CURSOR:hand' onclick=selectDate('" + (currdate+1) + "/" + (i-d.getDay()+1) + "/" + theYear.value + "')>" + (i-d.getDay()+1) + "</P>";
}
}
}
function theYear_onchange() {
display_calendar();
}
function theMonth_onchange() {
display_calendar();
}
function selectDate(s) {
//alert(s);
//s=Date.parse(s);
//alert(s);
window.returnValue = s;
window.close();
}
//-->
</SCRIPT>
<TITLE>Select Date</TITLE>
</HEAD>
<body Class ="DialogBody" LANGUAGE=javascript onload="return window_onload()">
<TABLE cellSpacing=1 cellPadding=1 border=1 align=center>
<TR>
<TD noWrap colSpan=5 align=center>
<input onclick="navigateMonth(-1)" type="Button" Value="< " id=Button1 name=Button1><SELECT id=theYear size=1 name=theYear LANGUAGE=javascript onchange="return theYear_onchange()">
<% For i =1940 to Year(Now) + 20 %>
<OPTION value=<%=i%> selected><%=i%></OPTION>
<%Next%>
</SELECT>
<!-- <OPTION value=1999>1999</OPTION><OPTION
value=2000>2000</OPTION><OPTION value=2001>2001</OPTION><OPTION
value=2002>2002</OPTION><OPTION value=2003>2003</OPTION><OPTION
value=2004>2004</OPTION><OPTION value=2005>2005</OPTION><OPTION
value=2006>2006</OPTION><OPTION value=2007>2007</OPTION><OPTION
value=2008>2008</OPTION><OPTION value=2009>2009</OPTION><OPTION
value=2010>2010</OPTION><OPTION value=2011>2011</OPTION><OPTION
value=2012>2012</OPTION>-->
<SELECT id=theMonth size=1 name=theMonth LANGUAGE=javascript onchange="return theMonth_onchange()">
<OPTION value=0 selected>January</OPTION>
<OPTION value=1>February</OPTION>
<OPTION value=2>March</OPTION>
<OPTION value=3>April</OPTION>
<OPTION value=4>May</OPTION>
<OPTION value=5>June</OPTION>
<OPTION value=6>July</OPTION>
<OPTION value=7>August</OPTION>
<OPTION value=8>September</OPTION>
<OPTION value=9>October</OPTION>
<OPTION value=10>November</OPTION>
<OPTION value=11>December</OPTION></SELECT><input onclick="navigateMonth(1)" type="Button" Value=" >" id=Button1 name=Button1>
</TD>
<TD noWrap colSpan=2 align=center><input onclick="selectDate('')" type="Button" Value="Clear" id=Button1 name=Button1></TD>
</TR>
<TR>
<TD noWrap><STRONG> Sun </STRONG></TD>
<TD noWrap><STRONG> Mon </STRONG></TD>
<TD noWrap><STRONG> Tue </STRONG></TD>
<TD noWrap><STRONG> Wed </STRONG></TD>
<TD noWrap><STRONG> Thu </STRONG></TD>
<TD noWrap><STRONG> Fri </STRONG></TD>
<TD noWrap><STRONG> Sat </STRONG></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD></TR>
<TR>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell></SPAN></TD>
<TD noWrap><SPAN id=thisCell LANGUAGE=javascript onclick="alert(this.sourceIndex)"></SPAN></TD></TR>
</TABLE>
</BODY>
</HTML>
我得到了表格的草圖,但似乎有一個「thiscell」跨度的問題。
可能是什麼問題?
你的用戶使用什麼瀏覽器?你不能使用'HTML 5'日期選擇器,這會爲你節省很多時間。 –
它是如何體現的?會發生什麼,預計會發生什麼? – hoijui
我認爲其中一個問題是沒有多少瀏覽器支持HTML 3.2。而且,即使在HTML 3.2中,多個ID也是一個錯誤。那麼'language'屬性是什麼? –